| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace addons\StarChain\common\models;
- use addons\StarChain\common\enums\StarChainEnum;
- use addons\StarChain\common\models\Order as ModelsOrder;
- use common\models\order\Order;
- /**
- * 主商城订单模型
- * @package addons\StarChain\common\models
- */
- class MallOrder extends Order
- {
- /**
- * 获取商城订单
- *
- * @param integer $order_id
- * @return Order
- */
- public static function getOrder($order_id)
- {
- $model = self::find();
- // $model->select('id, user_id, mall_id, order_no, mobile, region_name, address, pay_status, receiver_name, order_source');
- return $model->where(['id' => $order_id])
- ->with(['detail' => function($query) {
- $query->select('id, order_id, num, goods_attr_id, goods_id')->with([
- 'goods' => function($query) {
- $query->select('id, goods_source');
- }
- ]);
- }])
- ->one();
- }
- /**
- * 获取地址
- *
- * @return array
- */
- public function getRegion()
- {
- $region = $this->region_name;
- list($province, $city, $area, $town) = explode(' ', $region);
- $town = $town ?? $area;
- $address = $this->address;
- return compact('province', 'city', 'area', 'town', 'address');
- }
- /**
- * 是否已经创建供应链订单
- *
- * @return boolean
- */
- public function hasChainOrder()
- {
- return ModelsOrder::find()->select('id')->where([
- 'mall_id' => $this->mall_id,
- 'order_no' => $this->order_no
- ])->one() ? true : false;
- }
- /**
- * 判断当前订单是否是供应链订单
- *
- * @return boolean
- */
- public function isChainOrder()
- {
- if (empty($this->detail)) return false;
-
- $goods_sources = array_map(function($goods) {
- return $goods->goods_source;
- }, array_column($this->detail, 'goods'));
- return array_unique($goods_sources) == [StarChainEnum::PLUGIN_SIGN];
- }
- /**
- * @return boolean
- */
- public function changeOrderSource()
- {
- $this->order_source = StarChainEnum::PLUGIN_SIGN;
- return $this->save();
- }
- }
|