GoodsBuyMinNotice.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/6/7
  6. * Time: 21:16
  7. */
  8. namespace app\common\services\notice\applet\buyer;
  9. use app\common\models\Order;
  10. use app\common\models\Notice;
  11. use app\common\services\notice\applet\AppletMessageNotice;
  12. use app\common\services\notice\BaseMessageBody;
  13. use app\common\services\notice\share\BackstageNoticeMember;
  14. use app\common\services\notice\share\GoodsNoticeData;
  15. use app\common\services\notice\share\OrderNoticeData;
  16. use app\common\services\notice\share\MiniNoticeTemplate;
  17. class GoodsBuyMinNotice extends BaseMessageBody
  18. {
  19. use OrderNoticeData,BackstageNoticeMember,MiniNoticeTemplate,GoodsNoticeData;
  20. public $orderModel;
  21. protected $goodsNum;//商品购买数量
  22. protected $goodsPrice;
  23. protected $orderStatus;//订单状态
  24. protected $goodName;
  25. public function __construct($order,$status)
  26. {
  27. $this->orderModel = $order;
  28. $this->orderStatus = $status;
  29. }
  30. public function organizeData()
  31. {
  32. // TODO: Implement organizeData() method.
  33. $this->data = [
  34. 'keyword1'=>['value'=> $this->member->nickname],// 会员姓名
  35. 'keyword2'=>['value'=> $this->order->order_sn],//订单号
  36. 'keyword3'=>['value'=> $this->goodName],// 物品名称
  37. 'keyword4'=>['value'=> $this->goodsNum],// 数量
  38. 'keyword5'=>['value'=> $this->goodsPrice],// 购买金额
  39. 'keyword6'=>['value'=> $this->getOrderTime($this->orderStatus)],//购买时间
  40. ];
  41. }
  42. public function sendMessage()
  43. {
  44. // TODO: Implement sendMessage() method.
  45. if (count($this->orderGoods) > 0) {
  46. $this->processData($this->orderModel);
  47. $this->getBackMember();
  48. $this->getGoodsBuy($this->goodsId);
  49. foreach ($this->orderGoods as $kk=>$vv) {
  50. $status = $this->getGoodsStatus($vv['goods_id']);
  51. if (in_array($vv['goods_id'],$this->goodsBuy) && $status) {
  52. $option_title = empty($vv->goods_option_title) ? "" : $vv->goods_option_title;
  53. $this->goodsNum = $vv['total'];
  54. $this->goodsPrice = $vv['goods_price'];
  55. $this->goodName = $vv['title'].$option_title;
  56. $openId = $this->getGoodsMember($vv['goods_id']);
  57. $this->getTemplate("购买成功通知");
  58. $this->organizeData();
  59. $result = (new AppletMessageNotice($this->temp_id,$openId,$this->data,[],2))->sendMessage();
  60. if ($result['status'] == 0) {
  61. \Log::debug($result['message']);
  62. }
  63. }
  64. }
  65. }
  66. }
  67. private function getOrderTime($status)
  68. {
  69. if ($status == 1) {
  70. $order_time = $this->timeData['create_time'];
  71. } else if ($status == 2) {
  72. $order_time = $this->timeData['pay_time'];
  73. } else if ($status == 3) {
  74. $order_time = $this->timeData['finish_time'];
  75. }
  76. return $order_time;
  77. }
  78. private function getGoodsMember($goods_id)
  79. {
  80. if (count($this->goodsBuy) > 0) {
  81. foreach ($this->goodsBuy as $kk=>$vv) {
  82. if ($vv['goods_id'] == $goods_id) {
  83. $openid = empty($vv['has_one_mini']) ? 0 : $vv['has_one_mini'];
  84. return $openid;
  85. }
  86. }
  87. }
  88. return 0;
  89. }
  90. private function getGoodsStatus($goods_id)
  91. {
  92. if (count($this->goodsBuy) > 0) {
  93. foreach ($this->goodsBuy as $kk=>$vv) {
  94. if ($vv['goods_id'] == $goods_id && $vv['type'] == $this->orderStatus) {
  95. return true;
  96. }
  97. }
  98. }
  99. return false;
  100. }
  101. }