123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
- * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
- * @author pillar<ltmn@qq.com>
- * 会员卡管理
- */
- namespace app\ais\model;
- use app\common\facade\Inform;
- use think\Model;
- class AisCard extends Model{
- protected $pk = 'id';
- /**
- * 所属店铺
- * @return void
- */
- public function store(){
- return $this->hasOne('AisStore','id','store_id');
- }
- /**
- * 所属优惠券
- * @return void
- */
- public function coupon(){
- return $this->hasOne('AisCoupon','id','coupon_id');
- }
- /**
- * 订单号
- * @return void
- */
- public function cardorder(){
- return $this->hasMany('AisCardOrder','card_id','id');
- }
- /**
- * 开通用户列表
- * @return void
- */
- public function carduser(){
- return $this->hasMany('AisCardUser','card_id','id');
- }
- /**
- * 编辑创客的关联的优惠券
- * @param integer $vip_id
- * @param [type] $coupon_ids
- * @return void
- */
- public static function editCoupon(int $id,array $coupon_ids){
- $info = self::where(['id' => $id])->find();
- if(empty($info->coupon_ids)){
- $info->coupon_ids = implode(',',$coupon_ids);
- }else{
- $coupon_ida = explode(',',$info->coupon_ids);
- $ida = array_merge($coupon_ida,$coupon_ids);
- $info->coupon_ids = implode(',',$ida);
- }
- return $info->save();
- }
- /**
- * 锁定或取消
- * @param integer $id
- */
- public static function isLock(int $id,$member_miniapp_id){
- $result = self::where(['id' => $id])->field('is_lock,store_id')->find();
- $data['is_lock'] = $result['is_lock'] ? 0 : 1;
- if($data['is_lock'] == 0) {
- $store = AisStore::where('id', '=', $result->store_id)->find();
- }
- return self::where('id',$id)->update($data);
- }
- }
|