StoreCouponUser.php 3.7 KB

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