GoodsBuyNotice.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/6/7
  6. * Time: 21:46
  7. */
  8. namespace app\common\services\notice\official;
  9. use app\backend\modules\goods\models\Notice;
  10. use app\common\models\Order;
  11. use app\common\services\notice\BaseMessageBody;
  12. use app\common\services\notice\share\BackstageNoticeMember;
  13. use app\common\services\notice\share\OfficialNoticeTemplate;
  14. use app\common\services\notice\share\OrderNoticeData;
  15. use app\common\models\Member;
  16. class GoodsBuyNotice extends BaseMessageBody
  17. {
  18. protected $orderModel;
  19. protected $goodsNumber;//商品购买数量
  20. protected $goodsPrice;
  21. protected $orderStatus;//订单状态
  22. protected $goodName;
  23. use OrderNoticeData,OfficialNoticeTemplate,BackstageNoticeMember;
  24. public function __construct($order,$status)
  25. {
  26. $this->orderModel = $order;
  27. $this->orderStatus = $status;
  28. }
  29. public function organizeData()
  30. {
  31. // TODO: Implement organizeData() method.
  32. $this->data = [
  33. ['name' => '会员昵称', 'value' => $this->member->nickname],
  34. ['name' => '订单编号', 'value' => $this->order->order_sn],
  35. ['name' => '商品名称(含规格)', 'value' => $this->goodName],
  36. ['name' => '商品金额', 'value' => $this->goodsPrice],
  37. ['name' => '商品数量', 'value' => $this->goodsNumber],
  38. ['name' => '订单状态', 'value' => $this->order->status_name],
  39. ['name' => '时间', 'value' => $this->getOrderTime($this->orderStatus)],
  40. ];
  41. }
  42. public function sendMessage()
  43. {
  44. // TODO: Implement sendMessage() method.
  45. $this->processData($this->orderModel);
  46. $this->getTemplate('buy_goods_msg');
  47. if(
  48. (empty(\Setting::get('shop.notice')['notice_enable']['created']) && $this->orderStatus == 1) ||
  49. (empty(\Setting::get('shop.notice')['notice_enable']['paid']) && $this->orderStatus == 2) ||
  50. (empty(\Setting::get('shop.notice')['notice_enable']['received']) && $this->orderStatus == 3)
  51. ){
  52. return;
  53. }
  54. $this->getBackMember();
  55. if (count($this->orderGoods) > 0) {
  56. foreach ($this->orderGoods as $kk=>$vv) {
  57. $openids = $this->openids;
  58. //获取该商品设置的通知人
  59. $notices = Notice::where('goods_id',$vv['goods_id'])
  60. ->where('type',$this->orderStatus)
  61. ->first();
  62. if ($notices) {
  63. if (!$notices['uid']) {
  64. continue;
  65. }
  66. $saler = Member::uniacid()
  67. ->with('hasOneFans')
  68. ->where('uid',$notices['uid'])
  69. ->first();
  70. if (!$saler) {
  71. continue;
  72. }
  73. $saler = $saler->toArray();
  74. if($saler && !empty($saler['has_one_fans']) && !in_array($saler['has_one_fans']['openid'],$openids)){
  75. $openids[] = $saler['has_one_fans']['openid'];
  76. }
  77. }
  78. $this->goodsNumber = $vv['total'];
  79. $this->goodsPrice = $vv['goods_price'];
  80. $option_title = empty($vv->goods_option_title) ? "" : $vv->goods_option_title;
  81. $this->goodName = $vv['title'].$option_title;
  82. $this->organizeData();
  83. \Log::debug("新版公众号消息-商品1-".$kk,$this->template_id);
  84. \Log::debug("新版公众号消息-商品2-".$kk,$openids);
  85. \Log::debug("新版公众号消息-商品3-".$kk,$this->data);
  86. $result = (new OfficialMessageNotice($this->temp_id,0,$this->data,$openids,1,$this->url))->sendMessage();
  87. if ($result['status'] == 0) {
  88. \Log::debug($result['message'],$this->order);
  89. }
  90. }
  91. }
  92. }
  93. private function getOrderTime($status)
  94. {
  95. if ($status == 1) {
  96. $order_time = $this->timeData['create_time'];
  97. } else if ($status == 2) {
  98. $order_time = $this->timeData['pay_time'];
  99. } else if ($status == 3) {
  100. $order_time = $this->timeData['finish_time'];
  101. }
  102. return $order_time;
  103. }
  104. }