AisCard.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 会员卡管理
  7. */
  8. namespace app\ais\model;
  9. use app\common\facade\Inform;
  10. use think\Model;
  11. class AisCard extends Model{
  12. protected $pk = 'id';
  13. /**
  14. * 所属店铺
  15. * @return void
  16. */
  17. public function store(){
  18. return $this->hasOne('AisStore','id','store_id');
  19. }
  20. /**
  21. * 所属优惠券
  22. * @return void
  23. */
  24. public function coupon(){
  25. return $this->hasOne('AisCoupon','id','coupon_id');
  26. }
  27. /**
  28. * 订单号
  29. * @return void
  30. */
  31. public function cardorder(){
  32. return $this->hasMany('AisCardOrder','card_id','id');
  33. }
  34. /**
  35. * 开通用户列表
  36. * @return void
  37. */
  38. public function carduser(){
  39. return $this->hasMany('AisCardUser','card_id','id');
  40. }
  41. /**
  42. * 编辑创客的关联的优惠券
  43. * @param integer $vip_id
  44. * @param [type] $coupon_ids
  45. * @return void
  46. */
  47. public static function editCoupon(int $id,array $coupon_ids){
  48. $info = self::where(['id' => $id])->find();
  49. if(empty($info->coupon_ids)){
  50. $info->coupon_ids = implode(',',$coupon_ids);
  51. }else{
  52. $coupon_ida = explode(',',$info->coupon_ids);
  53. $ida = array_merge($coupon_ida,$coupon_ids);
  54. $info->coupon_ids = implode(',',$ida);
  55. }
  56. return $info->save();
  57. }
  58. /**
  59. * 锁定或取消
  60. * @param integer $id
  61. */
  62. public static function isLock(int $id,$member_miniapp_id){
  63. $result = self::where(['id' => $id])->field('is_lock,store_id')->find();
  64. $data['is_lock'] = $result['is_lock'] ? 0 : 1;
  65. if($data['is_lock'] == 0) {
  66. $store = AisStore::where('id', '=', $result->store_id)->find();
  67. }
  68. return self::where('id',$id)->update($data);
  69. }
  70. }