PreGoodsTradeLog.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2023-01-11
  8. * Time: 14:43
  9. */
  10. namespace app\frontend\modules\order\models;
  11. use app\backend\modules\goods\models\GoodsTradeSet;
  12. use app\common\models\order\GoodsTradeLog;
  13. use Illuminate\Support\Carbon;
  14. class PreGoodsTradeLog extends GoodsTradeLog
  15. {
  16. protected $order;
  17. /**
  18. * @param PreOrder $order
  19. */
  20. public function setOrder(PreOrder $order)
  21. {
  22. $this->order = $order;
  23. $goods_trade_collect = $this->newCollection();
  24. foreach ($this->order->orderGoods as $good) {
  25. $goods_trade_set = GoodsTradeSet::where('goods_id', $good->goods_id)->first();
  26. if (!$goods_trade_set || !$goods_trade_set->arrived_day || !app('plugins')->isEnabled('address-code')) {
  27. continue;
  28. }
  29. $arrived_day = $goods_trade_set->arrived_day;
  30. $arrived_word = $goods_trade_set->arrived_word;
  31. if ($arrived_day > 1) {
  32. $arrived_day -= 1;
  33. $time_format = Carbon::createFromTimestamp(time())->addDays($arrived_day)->format('Y-m-d');
  34. } else {
  35. $time_format = Carbon::createFromTimestamp(time())->format('Y-m-d');
  36. }
  37. $time_format .= " {$goods_trade_set->arrived_time}:00";
  38. $timestamp = strtotime($time_format);
  39. if ($timestamp < time()) {
  40. $timestamp += 86400;
  41. }
  42. $show_time = ltrim(date('m', $timestamp), '0').'月';
  43. $show_time .= ltrim(date('d', $timestamp), '0').'日';
  44. $show_time .= $goods_trade_set->arrived_time;
  45. $show_time_word = str_replace('[送达时间]', $show_time, $arrived_word);
  46. $pre_goods_trade_log = new PreGoodsTradeLog([
  47. 'goods_id' => $good->goods_id,
  48. 'show_time_word' => $show_time_word,
  49. ]);
  50. $goods_trade_collect->push($pre_goods_trade_log);
  51. }
  52. if (!$goods_trade_collect->isEmpty()) {
  53. $this->order->setRelation('goodsTradeLog', $goods_trade_collect);
  54. }
  55. }
  56. }