MessageNotice.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2018/3/13
  6. * Time: 11:59
  7. */
  8. namespace app\backend\modules\coupon\services;
  9. use app\common\models\Goods;
  10. use app\common\services\MessageService;
  11. use app\common\facades\Setting;
  12. use app\common\models\notice\MessageTemp;
  13. use app\common\models\Coupon;
  14. use app\backend\modules\member\models\Member;
  15. use app\common\services\SystemMsgService;
  16. use Yunshop\StoreCashier\common\models\Store;
  17. class MessageNotice extends MessageService
  18. {
  19. public static function couponNotice($couponDate,$memberId)
  20. {
  21. // //【系统消息通知】
  22. // (new SystemMsgService())->couponNotice($couponDate);
  23. $couponNotice = Setting::get('coupon.coupon_notice');
  24. $member = Member::getMemberInfoById($memberId);
  25. // dump(Coupon::getPromotionMethod($couponDate->id));exit();
  26. $temp_id = $couponNotice;
  27. if (!$temp_id) {
  28. return false;
  29. }
  30. static::messageNotice($temp_id,$couponDate, $member);
  31. return true;
  32. }
  33. public static function messageNotice($temp_id, $couponId, $member, $uniacid = '')
  34. {
  35. $couponDate = Coupon::getCouponById($couponId);
  36. //优惠方式
  37. $coupon_mode = Coupon::getPromotionMethod($couponDate->id);
  38. if($coupon_mode['type'] == 1) {
  39. $coupon_mode['content'] = "立减".floatval($coupon_mode['mode'])."元";
  40. } elseif ($coupon_mode['type'] == 2) {
  41. $coupon_mode['content'] = "打".floatval($coupon_mode['mode'])."折";
  42. }
  43. $scope = '';
  44. //适用范围
  45. $coupon_scope = Coupon::getApplicableScope($couponDate->id);
  46. if($coupon_scope['type'] == 0) {
  47. $scope = "全类适用";
  48. } elseif ($coupon_scope['type'] == 1) {
  49. $category_name = implode(',',Coupon::where('id', '=', $couponDate->id)->value('categorynames'));
  50. $scope = "".$category_name."类商品可用";
  51. } elseif ($coupon_scope['type'] == 2) {
  52. $goods_name = implode(',',Coupon::where('id', '=', $couponDate->id)->value('goods_names'));
  53. $scope = "".$goods_name."商品可用";
  54. } elseif ($coupon_scope['type'] == 4 || $coupon_scope['type'] == 5) {//4 多门店可用 5 单门店可用
  55. $goods_name = implode(',',Coupon::where('id', '=', $couponDate->id)->value('storenames'));
  56. $scope = "".$goods_name."门店可用";
  57. } elseif ($coupon_scope['type'] == 9) {
  58. $use_condition = unserialize(Coupon::where('id', '=', $couponDate->id)->value('use_conditions'));
  59. if (empty($use_condition)) {
  60. $scope = "无适用范围";
  61. }
  62. if (app('plugins')->isEnabled('store-cashier')) {
  63. if ($use_condition['is_all_store'] == 1) {
  64. $scope .= "全部门店、";
  65. } else {
  66. $scope = implode(',', Store::uniacid()->whereIn('id', $use_condition['store_ids'])->pluck('store_name')->all()).'、';
  67. }
  68. }
  69. if ($use_condition['is_all_good'] == 1) {
  70. $scope .= "平台自营商品";
  71. } else {
  72. $scope = implode(',', Goods::uniacid()->whereIn('id', $use_condition['good_ids'])->pluck('title')->all());
  73. }
  74. }
  75. //结束时间
  76. $coupon_time_end = Coupon::getTimeLimit($couponDate->id);
  77. if($coupon_time_end['type'] == 0) {
  78. if ($coupon_time_end['time_end'] == 0) {
  79. $time_end = "无时间限制";
  80. } else {
  81. $time_end = date('Y-m-d H:i:s',(strtotime('+'.$coupon_time_end['time_end'].'day',time())));
  82. }
  83. } elseif ($coupon_time_end['type'] == 1) {
  84. $time_end = $coupon_time_end['time_end'];
  85. }
  86. //优惠券使用条件
  87. if($couponDate->enough == 0) {
  88. $coupon_enough = "无门槛";
  89. } else {
  90. $coupon_enough = "满".$couponDate->enough."元可用";
  91. }
  92. $params = [
  93. ['name' => '昵称', 'value' => $member['nickname']],
  94. ['name' => '优惠券名称', 'value' => $couponDate->name],
  95. ['name' => '优惠券使用范围', 'value' => $scope],
  96. ['name' => '优惠券使用条件', 'value' => $coupon_enough],
  97. ['name' => '优惠方式', 'value' => $coupon_mode['content']],
  98. ['name' => '过期时间', 'value' => $time_end],
  99. ['name' => '获得时间', 'value' => date('Y-m-d H:i:s', time())],
  100. ];
  101. $msg = MessageTemp::getSendMsg($temp_id, $params);
  102. if (!$msg) {
  103. return false;
  104. }
  105. $news_link = MessageTemp::find($temp_id)->news_link;
  106. $news_link = $news_link ?:'';
  107. MessageService::notice(MessageTemp::$template_id, $msg, $member->uid, $uniacid,$news_link);
  108. }
  109. }