PreOutsideOrder.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/1/13
  8. * Time: 15:18
  9. */
  10. namespace app\outside\modules\order\models;
  11. use app\common\exceptions\ApiException;
  12. use app\frontend\modules\order\models\PreOrder;
  13. use app\common\modules\order\OrderCollection;
  14. use app\frontend\modules\order\services\OrderService;
  15. use app\outside\modes\OutsideOrder;
  16. /**
  17. * Class PreOutsideOrder
  18. * @property OrderCollection orders
  19. * @package app\outside\modules\order\models
  20. */
  21. class PreOutsideOrder extends OutsideOrder
  22. {
  23. /**
  24. * @var OrderCollection
  25. */
  26. public $orders;
  27. public function setOrders(OrderCollection $orders)
  28. {
  29. $this->orders = $orders;
  30. $this->initAttributes();
  31. }
  32. protected function initAttributes()
  33. {
  34. $this->fill([
  35. 'uniacid' => \YunShop::app()->uniacid,
  36. 'total_price' => $this->orders->sum('price'),
  37. 'outside_sn' => request()->input('outside_sn'),
  38. 'order_ids' => $this->orders->pluck('id'),
  39. 'trade_sn' => self::createSn(),
  40. ]);
  41. }
  42. /**
  43. * @throws ApiException
  44. */
  45. public function store()
  46. {
  47. $this->save();
  48. if ($this->id === null) {
  49. throw new ApiException('第三方订单请求记录保存失败');
  50. }
  51. $this->orders()->attach($this->order_ids);
  52. }
  53. }