StoreCouponUser.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\controller\ump;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\article\Article as ArticleModel;
  5. use app\admin\model\wechat\WechatUser;
  6. use crmeb\services\UtilService as Util;
  7. use crmeb\services\JsonService as Json;
  8. use app\admin\model\ump\StoreCoupon as CouponModel;
  9. use app\admin\model\ump\StoreCouponUser as CouponUserModel;
  10. use app\admin\model\wechat\WechatUser as UserModel;
  11. /**
  12. * 优惠券发放记录控制器
  13. * Class StoreCategory
  14. * @package app\admin\controller\system
  15. */
  16. class StoreCouponUser extends AuthController
  17. {
  18. /**
  19. * @return mixed
  20. */
  21. public function index()
  22. {
  23. $where = Util::getMore([
  24. ['status', ''],
  25. ['is_fail', ''],
  26. ['coupon_title', ''],
  27. ['nickname', ''],
  28. ], $this->request);
  29. $this->assign('where', $where);
  30. $this->assign('list',CouponUserModel::systemPage($where));
  31. return $this->fetch();
  32. }
  33. /**
  34. * 给已关注的用户发放优惠券
  35. * @param $id
  36. */
  37. public function grant_subscribe($id)
  38. {
  39. if (!$id) return Json::fail('数据不存在!');
  40. $coupon = CouponModel::get($id)->toArray();
  41. if (!$coupon) return Json::fail('数据不存在!');
  42. $user = UserModel::getSubscribe('uid');
  43. if (!CouponUserModel::setCoupon($coupon, $user))
  44. return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
  45. else
  46. return Json::successful('发放成功!');
  47. }
  48. /**
  49. * 给所有人发放优惠券
  50. * @param $id
  51. */
  52. public function grant_all($id)
  53. {
  54. if (!$id) return Json::fail('数据不存在!');
  55. $coupon = CouponModel::get($id)->toArray();
  56. if (!$coupon) return Json::fail('数据不存在!');
  57. $user = UserModel::getUserAll('uid');
  58. if (!CouponUserModel::setCoupon($coupon, $user))
  59. return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
  60. else
  61. return Json::successful('发放成功!');
  62. }
  63. /**
  64. * 发放优惠券到指定个人
  65. * @param $id
  66. * @param $uid
  67. * @return \think\response\Json
  68. */
  69. public function grant($id, $uid)
  70. {
  71. if (!$id) return Json::fail('数据不存在!');
  72. $coupon = CouponModel::get($id)->toArray();
  73. if (!$coupon) return Json::fail('数据不存在!');
  74. $user = explode(',', $uid);
  75. if (!CouponUserModel::setCoupon($coupon, $user))
  76. return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
  77. else
  78. return Json::successful('发放成功!');
  79. }
  80. public function grant_group($id)
  81. {
  82. $data = Util::postMore([
  83. ['group', 0]
  84. ]);
  85. if (!$id) return Json::fail('数据不存在!');
  86. $coupon = CouponModel::get($id)->toArray();
  87. if (!$coupon) return Json::fail('数据不存在!');
  88. $user = WechatUser::where('groupid', $data['group'])->column('uid', 'uid');
  89. if (!CouponUserModel::setCoupon($coupon, $user))
  90. return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
  91. else
  92. return Json::successful('发放成功!');
  93. }
  94. public function grant_tag($id)
  95. {
  96. $data = Util::postMore([
  97. ['tag', 0]
  98. ]);
  99. if (!$id) return Json::fail('数据不存在!');
  100. $coupon = CouponModel::get($id)->toArray();
  101. if (!$coupon) return Json::fail('数据不存在!');
  102. $user = WechatUser::where("tagid_list", "LIKE", "%$data[tag]%")->column('uid', 'uid');
  103. if (!CouponUserModel::setCoupon($coupon, $user))
  104. return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
  105. else
  106. return Json::successful('发放成功!');
  107. }
  108. /**
  109. * 删除图文
  110. * @param $id
  111. * @return \think\response\Json
  112. */
  113. public function delete($id)
  114. {
  115. $res = CouponUserModel::del($id);
  116. if (!$res)
  117. return Json::fail('删除失败,请稍候再试!');
  118. else
  119. return Json::successful('删除成功!');
  120. }
  121. }