OrderNoticeData.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2020/6/4
  6. * Time: 10:05
  7. */
  8. namespace app\common\services\notice\share;
  9. Trait OrderNoticeData
  10. {
  11. public $order;
  12. public $orderGoods;//订单商品
  13. public $address;//收货地址
  14. public $timeData;//时间数据
  15. public $member;//会员相关信息
  16. public $fans;//单个会员的fans(公众号)
  17. public $miniFans;//单个会员的fans(小程序)
  18. public $goodsId;//商品ID
  19. public $goodsTitle='';//商品标题
  20. public $goodsNum;//商品购买数量
  21. public $packageGoodsTitle='';// 包裹商品标题
  22. public function processData($order)
  23. {
  24. //订单数据整理
  25. $this->order = $order;
  26. //会员数据整理
  27. $this->member = $order->belongsToMember;
  28. //单个会员的Fans(公众号)
  29. $this->fans = $order->belongsToMember->hasOneFans;
  30. //单个会员的Fans(小程序)
  31. $this->miniFans = $order->belongsToMember->hasOneMiniApp;
  32. //地址数据整理
  33. $this->address = $order->address;
  34. //时间数据整理
  35. $this->timeData = [
  36. 'create_time' => $order->create_time->toDateTimeString(),
  37. 'pay_time' => $order->pay_time->toDateTimeString(),
  38. 'finish_time' => $order->finish_time->toDateTimeString(),
  39. 'cancel_time' => $order->cancel_time->toDateTimeString(),
  40. 'send_time' => $order->send_time->toDateTimeString()
  41. ];
  42. //订单商品数据整理
  43. $orderGoods = $order->hasManyOrderGoods()->get();
  44. $orderGoods = empty($orderGoods) ? [] : $orderGoods->toArray();
  45. if (count($orderGoods)>0) {
  46. $this->orderGoods = $orderGoods;
  47. foreach ($orderGoods as $kk=>$vv) {
  48. $this->goodsId[] = $vv['goods_id'];
  49. $this->goodsTitle .= $vv['title'];
  50. if ($vv['goods_option_title']) {
  51. $this->goodsTitle .= '[' . $vv['goods_option_title'] . ']';
  52. }
  53. $this->goodsTitle .= '*' . $vv['total'] . ',';
  54. $this->goodsNum += $vv['total'];
  55. }
  56. $this->goodsTitle = rtrim($this->goodsTitle,',');
  57. }
  58. //订单包裹商品数据整理
  59. if($this->order['expressmany']->count()){
  60. $packageList=$this->order['expressmany']->last()['hasManyOrderPackage'];
  61. $this->timeData['package_send_time']=$this->order['expressmany']->last()['created_at']->toDateTimeString();
  62. if($packageList->count()>0){
  63. foreach($packageList as $key=>$val){
  64. $this->packageGoodsTitle .= ($val['orderGoods']->title);
  65. if ($val['orderGoods']->goods_option_title) {
  66. $this->packageGoodsTitle .= '[' . $val['orderGoods']->goods_option_title . ']';
  67. }
  68. $this->packageGoodsTitle .= '*' . $val['total'] . ',';
  69. }
  70. }
  71. $this->packageGoodsTitle=rtrim($this->packageGoodsTitle,',');
  72. }
  73. }
  74. }