Card.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\allwin\model;
  9. use app\common\facade\Inform;
  10. use think\Model;
  11. class Card extends Model{
  12. protected $pk = 'id';
  13. protected $table = 'ai_allwin_card';
  14. /**
  15. * 所属店铺
  16. * @return void
  17. */
  18. public function store(){
  19. return $this->hasOne('AllwinStore','id','store_id');
  20. }
  21. /**
  22. * 所属优惠券
  23. * @return void
  24. */
  25. public function coupon(){
  26. return $this->hasOne('Coupon','id','coupon_id');
  27. }
  28. /**
  29. * 编辑创客的关联的优惠券
  30. * @param integer $vip_id
  31. * @param [type] $coupon_ids
  32. * @return void
  33. */
  34. public static function editCoupon(int $id,array $coupon_ids){
  35. $info = self::where(['id' => $id])->find();
  36. if(empty($info->coupon_ids)){
  37. $info->coupon_ids = implode(',',$coupon_ids);
  38. }else{
  39. $coupon_ida = explode(',',$info->coupon_ids);
  40. $ida = array_merge($coupon_ida,$coupon_ids);
  41. $info->coupon_ids = implode(',',$ida);
  42. }
  43. return $info->save();
  44. }
  45. /**
  46. * 锁定或取消
  47. * @param integer $id
  48. */
  49. public static function isLock(int $id,$member_miniapp_id){
  50. $result = self::where(['id' => $id])->field('is_lock,store_id')->find();
  51. $data['is_lock'] = $result['is_lock'] ? 0 : 1;
  52. if($data['is_lock'] == 0) {
  53. $store = AllwinStore::where('id', '=', $result->store_id)->find();
  54. if ($store) {
  55. //通知申请者到微信
  56. Inform::sms($store->manage_uid,$member_miniapp_id,['title' =>'业务进展通知','type' => '储值活动申请','content' =>'您的储值活动申请已经通过审核','state' => '成功']);
  57. }
  58. }
  59. return self::where('id',$id)->update($data);
  60. }
  61. }