$info) { $ext['activity_discount_infos'][$key]['activity_type_text'] = Activity::getTypeList()[$info['activity_type']]; $ext['activity_discount_infos'][$key]['format_text'] = Activity::formatDiscountTags($info['activity_type'], array_merge([ 'type' => $info['rule_type'], ], $info['discount_rule'])); } } return $ext; } protected function getStatus($data, $type) { $btns = []; $status_name = ''; $status_desc = ''; switch ($this->status_code) { case 'cancel': $status_name = '已取消'; $status_desc = '订单已取消'; $btns[] = 'delete'; // 删除订单 break; case 'invalid': $status_name = '交易关闭'; $status_desc = '交易关闭'; $btns[] = 'delete'; // 删除订单 break; case 'nopay': $status_name = '待付款'; $status_desc = '等待买家付款'; $btns[] = 'cancel'; // 取消订单 $btns[] = 'pay'; // 支付 break; // 已支付的 case 'commented': $status_name = '已评价'; $status_desc = '订单已评价'; $dispatchType = $this->getItemDispatchType($this->item); if (in_array('express', $dispatchType)) { $btns[] = 'express'; // 查看物流 } break; case 'nocomment': $status_name = '待评价'; $status_desc = '等待买家评价'; $dispatchType = $this->getItemDispatchType($this->item); if (in_array('express', $dispatchType)) { $btns[] = 'express'; // 查看物流 } break; case 'noget': $dispatchType = $this->getItemDispatchType($this->item); $status_name = '待收货'; $status_desc = '等待买家收货'; if (in_array('express', $dispatchType)) { $btns[] = 'express'; // 查看物流 } else { if (count($dispatchType) == 1) { // item 只有一种发货方式 $dispatch_type = $dispatchType[0] ?? ''; switch($dispatch_type) { case 'selfetch': $status_name = '待提货/到店'; $status_desc = '等待买家提货/到店'; break; case 'regiment': $status_name = '待提货/到团点'; $status_desc = '等待买家提货/团点'; break; case 'store': $status_name = '待取货'; $status_desc = '卖家上门配送中'; break; } } } break; case 'nosend': $dispatchType = $this->getItemDispatchType($this->item); $status_name = '待发货'; $status_desc = '等待卖家发货'; if (in_array('store', $dispatchType)) { $status_name = '待配送'; $status_desc = '等待卖家上门配送'; } else if (in_array('selfetch', $dispatchType)) { $status_name = '待备货'; $status_desc = '等待卖家备货'; }else if (in_array('regiment', $dispatchType)) { $status_name = '待备货'; $status_desc = '等待团点备货'; } break; case 'refund_finish': $status_name = '退款完成'; $status_desc = '订单退款完成'; break; case 'refund_ing': $status_name = '退款处理中'; $status_desc = '退款处理中'; break; case 'groupon_ing': $status_name = '等待成团'; $status_desc = '等待拼团成功'; break; case 'groupon_invalid': $status_name = '拼团失败'; $status_desc = '拼团失败'; break; // 已支付的结束 case 'finish': $status_name = '交易完成'; $status_desc = '交易完成'; $btns[] = 'delete'; // 删除订单 break; } $ext_arr = json_decode($data['ext'], true); // 是拼团订单 if ( strpos($data['activity_type'], 'groupon') !== false && isset($ext_arr['groupon_id']) && $ext_arr['groupon_id'] ) { $btns[] = 'groupon'; // 拼团详情 } return $type == 'status_name' ? $status_name : ($type == 'btns' ? $btns : $status_desc); } private function getItemDispatchType($item = []) { $dispatchType = []; foreach ($this->item as $key => $item) { // 获取 item status $dispatchType[] = $item['dispatch_type']; } $dispatchType = array_unique(array_filter($dispatchType)); // 过滤重复,过滤空值 return $dispatchType; } /* -------------------------- 访问器 ------------------------ */ /* -------------------------- 模型关联 ------------------------ */ public function item() { return $this->hasMany(\addons\shopro\model\OrderItem::class, 'order_id', 'id'); } /** * 只保留基本信息 */ public function itemSlim() { return $this->hasMany(\addons\shopro\model\OrderItem::class, 'order_id', 'id') ->field('id,user_id,order_id,goods_id,goods_type,goods_sku_price_id,activity_id,activity_type,item_goods_sku_price_id,goods_sku_text,goods_title,goods_image,goods_original_price,discount_fee,goods_price,goods_num,dispatch_status,dispatch_type,dispatch_id,store_id,aftersale_status,comment_status,refund_status,ext'); } // 拼团只有一个商品,可以使用这个 public function firstItem() { return $this->hasOne(\addons\shopro\model\OrderItem::class, 'order_id', 'id'); } /* -------------------------- 模型关联 ------------------------ */ }