-1], [['page',], 'default', 'value' => 1], [['dateStart', 'dateEnd', 'express_type', 'md_name', 'order_no', 'goods_name', 'mobile'], 'trim'], [['seller_comments', 'flag', 'user_name', 'send_time'], 'string'], [['export', 'activity_type', 'mobiles', 'openids'], 'safe'], [['fields', 'is_offline', 'is_delivery', 'shop_list', 'book_name', 'book_mobile', 'name'], 'safe'], [['maiyatian', 'maiyatian_delivery_status', 'maiyatian_order_status', 'maiyatian_logistic_tag', 'province_id', 'city_id', 'district_id', 'id'], 'safe'], [['keloop', 'keloop_delivery_status'], 'safe'], [['status_ext', 'worker_name', 'worker_tel'], 'safe'], [['booking_time_start', 'booking_time_end', 'worker_id', 'is_wastore', 'pay_type', 'pay_time_start', 'pay_time_end'], 'safe'], ['cat_id','integer'], [['mch', 'mch_id', 'mch_common_cat_id'], 'safe'], ['cat_id','default','value'=>0] ]; } public function search($is_scan_pay = false, $arr = []) { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $addSelect = []; $query = Order::find()->alias('o')->where(['!=','o.order_type', Order::ORDER_TYPE_Adopt]); if($this->id) { $oids = explode(',',$this->id); $query->andWhere(['in','o.id',$oids]); } if($this->order_type == Order::ORDER_TYPE_WORKER){ $query->leftJoin(['woe' => WorkerOrderExt::tableName()], 'o.id = woe.order_id'); $query->leftJoin(['w' => Worker::tableName()], 'w.id = woe.worker_id'); if($this->status_ext > -1){ $this->status = -1; $query->andWhere([ 'woe.status_ext' => $this->status_ext, ]); } if($this->worker_name){ $query->andWhere(['like', 'w.name', $this->worker_name]); } if($this->worker_tel){ $query->andWhere(['like', 'w.tel', $this->worker_tel]); } }else{ $query->andWhere(['!=','o.order_type', Order::ORDER_TYPE_WORKER]); } if ($this->order_type == 2) { $query->leftJoin(['boe' => BookingOrderExt::tableName()], 'o.id = boe.order_id'); $addSelect = array_merge($addSelect, ['boe.worker_id', 'boe.worker_name', 'boe.status_ext', 'boe.time_sys_confirm', 'boe.user_revoke', 'boe.user_revoke_reason']); $addSelect = array_merge($addSelect, ['IF(boe.booking_time_end < "'.date('Y-m-d H:i:s').'" AND boe.status_ext < '. BookingOrderExt::STATUS_EXT_START .', 1, 0) booking_time_out']); if($this->booking_time_start){ $query->andWhere(['>=', 'boe.booking_time_end', $this->booking_time_start]); } if($this->booking_time_end){ $query->andWhere(['<=', 'boe.booking_time_start', $this->booking_time_end]); } if(isset($this->worker_id)){ $query->andWhere(['boe.worker_id' => $this->worker_id]); } if($this->status_ext == 500){ //已超时 $query->andWhere(['and', ['<', 'boe.status_ext', BookingOrderExt::STATUS_EXT_START], ['<', 'boe.booking_time_end', date('Y-m-d H:i:s')]]); }else if($this->status_ext == 600){ //未分配 $query->andWhere(['boe.worker_id' => 0]); }else{ isset($this->status_ext) && $this->status_ext > -1 && $query->andWhere(['boe.status_ext' => $this->status_ext]); } } if (!$this->user_id && empty($this->order_id)) { if ($this->order_origin) { $query->andWhere(['o.order_origin' => $this->order_origin]); }else{ $query->andWhere(['!=', 'o.order_origin',Order::ORDER_SOURCE_CASHIER]); } } if(isset($this->pay_type) && $this->pay_type > -1){ $query->andWhere(['o.pay_type' => $this->pay_type]); } if($this->pay_time_start){ $query->andWhere(['>=', 'o.pay_time', strtotime($this->pay_time_start)]); } if($this->pay_time_end){ $query->andWhere(['<=', 'o.pay_time', strtotime($this->pay_time_end)]); } if($this->is_wastore){ $query->andWhere(['o.is_wastore' => 1]); } if($this->maiyatian){ $queryMaiyatian = (new Query())->select('order_no')->from(DeliveryMaiyatian::tableName())->where(['store_id' => $this->store_id]); if($this->maiyatian_delivery_status){ $queryMaiyatian->andWhere(['delivery_status' => $this->maiyatian_delivery_status]); } if($this->maiyatian_order_status){ $queryMaiyatian->andWhere(['order_status' => $this->maiyatian_order_status]); } if($this->maiyatian_logistic_tag){ $queryMaiyatian->andWhere(['logistic_tag' => $this->maiyatian_logistic_tag]); } $query->andWhere(['order_no' => $queryMaiyatian]); } if($this->keloop){ $queryKeloop = (new Query())->select('order_no')->from(DeliveryKeloop::tableName())->where(['store_id' => $this->store_id]); if($this->keloop_delivery_status){ $queryKeloop->andWhere(['delivery_status' => $this->keloop_delivery_status]); } $query->andWhere(['order_no' => $queryKeloop]); } if($this->activity_type == Order::ACTIVITY_TYPE_CUT_PRICE){ $query->andWhere(['>', 'o.activity_cut_price_order_id', 0]); } if($this->activity_type == Order::ACTIVITY_WECHAT_ROOM){ $query->andWhere(['>', 'o.activity_wechat_room_id', 0]); } if(intval($this->activity_type) === Order::ACTIVITY_PT_PRICE){ $query->andWhere(['>', 'o.pt_order_id', 0]); } if (!empty($this->user_id)) { $query->andWhere(['o.user_id' => $this->user_id, 'o.trade_status' => [Order::ORDER_FLOW_NO_SEND, Order::ORDER_FLOW_SEND, Order::ORDER_FLOW_CONFIRM]]); $this->mch = -1; } if (!empty($this->province_id)) { $query->andWhere(['province_id' => $this->province_id]); } if (!empty($this->city_id)) { $query->andWhere(['city_id' => $this->city_id]); } if (!empty($this->district_id)) { $query->andWhere(['district_id' => $this->district_id]); } if(intval($this->activity_type) === Order::ACTIVITY_SECKILL_PRICE){ $query->andWhere(['>', 'o.seckill_order_id', 0]); } if (isset($this->mch) && $this->mch == 1) { if ($this->mch_id > 0) { $query->andWhere(['o.mch_id' => $this->mch_id]); }else{ $query->andWhere(['>', 'o.mch_id', 0]); // $query->andWhere(['o.mch_id' => \app\models\Mch::find()->select('id')->where(['store_id' => get_store_id(), 'is_delete' => 0])]); } if($this->brands_id > 0){ $mchList = Mch::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'brands_id' => $this->brands_id])->select('id')->column(); $query->andWhere(['o.mch_id' => $mchList]); } if (isset($this->mch_common_cat_id) && $this->mch_common_cat_id > 0) { $query->andWhere(['o.mch_id' => \app\models\Mch::find()->select('id')->where(['store_id' => $this->store_id, 'mch_common_cat_id' => $this->mch_common_cat_id])]); } }elseif (isset($this->mch) && $this->mch == -1) { //不区分入驻商和平台 }else{ $query->andWhere(['o.mch_id' => 0]); } if ($arr['givingGifts'] == 1) { $query->andWhere(['o.order_type' => Order::ORDER_TYPE_GIVING_GIFTS]); if(isset($arr['givingGifts_received']) && $arr['givingGifts_received'] > -1){ if ($arr['givingGifts_received'] == 1) { $query->andWhere(['>', 'o.giving_gifts_received_user_id', 0]); } else { $query->andWhere(['o.giving_gifts_received_user_id' => 0]); } } }else{ // $query->andWhere(['!=', 'o.order_type', Order::ORDER_TYPE_GIVING_GIFTS]); } if ($arr['localPublicRanking'] == 1) { $queryPR = LocalPublicRankingTask::find()->select('order_id')->where(['store_id' => $this->store_id]); if($arr['localPublicRanking_parentNickname']){ $queryPR->andWhere(['parent_user_id' => User::find()->select('id')->where(['like', 'nickname', $arr['localPublicRanking_parentNickname']])]); } $query->andWhere(['o.id' => $queryPR]); } if (get_md_id() > 0) { $query->andWhere(['o.md_id' => get_md_id()]); } if (!empty($this->order_type) && in_array($this->order_type, [0, 1, 2, 3, Order::ORDER_TYPE_WORKER, Order::ORDER_TYPE_INTEGRAL])) { $query->andWhere([ 'o.order_type' => $this->order_type ]); } $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } $order_ids = []; if ($this->supplier_id && !$this->type) { $supplier = Supplier::findOne(['cloud_supplier_id' => $this->supplier_id, 'is_delete' => 0]); if ($supplier) { $order_ids = OrderTransit::find()->alias('ot')->leftJoin(['o' => Order::tableName()], 'ot.order_id = o.id') ->where(['o.store_id' => $this->store_id, 'ot.cloud_supplier_id' => $supplier->cloud_supplier_id])->select('ot.order_id')->column(); } $query->andWhere(['o.id' => $order_ids]); } if ($admin_id && !in_array($admin->type, [Admin::ADMIN_TYPE_SAAS_STAFF, Admin::ADMIN_TYPE_STAFF])) { if ($this->store_id < 0) { $salesman_id = $this->salesman_id; $salesman_where = [ 'admin_id' => $admin_id, 'is_delete' => 0 ]; if ($salesman_id) { $salesman_where['id'] = $salesman_id; } $ids = Salesman::find()->where($salesman_where)->select('id')->asArray()->all(); $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $store_query = Store::find()->where(['is_delete' => 0]); if ($this->salesman_id) { $store_query->andWhere(['in', 'salesman_id', array_column($ids, 'id')]); } else { if($area_level == 1){ $store_query->andWhere([ 'or', ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id], ['admin_id' => $admin_id], ['in', 'salesman_id', array_column($ids, 'id')] ]); } elseif ($area_level == 2){ $store_query->andWhere([ 'or', ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id], ['admin_id' => $admin_id], ['in', 'salesman_id', array_column($ids, 'id')] ]); } elseif ($area_level == 3){ $store_query->andWhere([ 'or', ['province_id' => $admin_model->province_id], ['admin_id' => $admin_id], ['in', 'salesman_id', array_column($ids, 'id')] ]); } else { $store_query->andWhere([ 'or', ['admin_id' => $admin_id], ['in', 'salesman_id', array_column($ids, 'id')] ]); } } $ids = $store_query->select('id')->column(); } } if (!empty($this->name)) { $query->andWhere(['o.name' => $this->name]); } if (!$this->type) { if (!empty($ids) || ($admin->type == Admin::ADMIN_TYPE_BD_AGENT && $this->store_id < 0)) { $query->andWhere(['o.store_id' => $ids]); } else { $query->andWhere([ 'o.store_id' => $this->store_id ]); } } $query->leftJoin(['u' => User::tableName()], 'u.id = o.user_id') ->leftJoin(['od' => OrderDetail::tableName()], 'od.order_id=o.id'); switch ($this->status) { case 0: $query->andWhere(['<>', 'o.trade_status', Order::ORDER_FLOW_CANCEL])->andWhere(['o.is_delete' => Order::IS_DELETE_FALSE, 'o.is_pay' => Order::IS_PAY_FALSE]); break; case 1: $query->andWhere([ 'o.trade_status' => Order::ORDER_FLOW_NO_SEND, 'o.is_delete' => Order::IS_DELETE_FALSE ])->andWhere(['or', ['o.is_pay' => Order::IS_PAY_TRUE], ['o.pay_type' => Order::PAY_TYPE_COD]]); break; case 2: $query->andWhere([ 'o.trade_status' => Order::ORDER_FLOW_SEND, 'o.is_delete' => Order::IS_DELETE_FALSE ])->andWhere(['or', ['o.is_pay' => Order::IS_PAY_TRUE], ['o.pay_type' => Order::PAY_TYPE_COD]]); break; case 3: $query->andWhere([ 'o.trade_status' => Order::ORDER_FLOW_CONFIRM, 'o.is_delete' => Order::IS_DELETE_FALSE ])->andWhere(['or', ['o.is_pay' => Order::IS_PAY_TRUE], ['o.pay_type' => Order::PAY_TYPE_COD]]); break; case 4: break; case 5: $query->andWhere(['or', ['o.trade_status' => Order::ORDER_FLOW_CANCEL], ['o.is_delete' => Order::IS_DELETE_TRUE]]); break; case 6: $query->andWhere(['and',['o.apply_delete' => Order::ORDER_APPLY_DELETE], ['!=', 'o.trade_status', Order::ORDER_FLOW_CANCEL]]); break; case 7: $query->andWhere(['o.apply_delete' => Order::ORDER_APPLY_DELETE, 'o.trade_status' => Order::ORDER_FLOW_NO_SEND]); break; default: if (empty($this->order_id)) { $query->andWhere([ 'o.is_delete' => Order::IS_DELETE_FALSE ]); } break; } if (get_params('is_recycle')) { $query->andWhere([ 'o.is_recycle' => Order::IS_DELETE_TRUE ]); } else { $query->andWhere([ 'o.is_recycle' => Order::IS_DELETE_FALSE ]); } if ($this->order_id && $this->order_id > 0) { $query->andWhere(['o.id' => $this->order_id]); } // TODO: // $commonOrderSearch = new CommonOrderSearch(); if (!$this->order_id) { // $query = $commonOrderSearch->search($query, $this); // $query = $commonOrderSearch->keyword($query, $this->keywordType, $this->keyword); if ($this->md_name) { $query->leftJoin(['md' => Md::tableName()], 'md.id=o.md_id')->andWhere(['like', 'md.name', $this->md_name]); } if ($this->order_no) { $query->andWhere(['like', 'o.order_no', $this->order_no]); } if ($this->mobile) { $query->andWhere([ 'or', ['like', 'o.mobile', $this->mobile], ['like', 'u.binding', $this->mobile], ]); } if ($this->goods_name) { $query->andWhere(['like', 'od.goods_name', $this->goods_name]); } if ($this->user_name) { $query->andWhere([ 'or', ['like', 'u.nickname', $this->user_name], ['u.binding' => SaasUser::find()->select('mobile')->where(['like', 'name', $this->user_name])], ['o.giving_gifts_received_user_id' => User::find()->select('id')->where(['binding' => SaasUser::find()->select('mobile')->where(['like', 'name', $this->user_name])])], ]); } } if ($this->dateStart) { $query->andWhere(['>=', 'o.created_at', strtotime($this->dateStart)]); } if ($this->dateEnd) { $query->andWhere(['<=', 'o.created_at', strtotime($this->dateEnd)]); } // TODO 这里处理自提订单中的分类搜索 if($this->cat_id > 0){ // 获取所有绑定这个分类ID的商品ID $goodsID = GoodsCat::find()->where(['is_delete'=>0,'cat_id'=>$this->cat_id])->select('goods_id')->column(); if(!empty($goodsID)){ $query->andWhere(['od.goods_id' => $goodsID]); } } if ($this->flag == Export::EXPORT) { $query_ex = clone $query; $list_ex = $query_ex; $export = new ExportList(); $export->is_offline = $this->is_offline; $export->is_delivery = $this->is_delivery; $export->order_type = 0; $export->fields = $this->fields; $export->dataTransform_new($list_ex); } if (!$this->order_id) { if(isset($this->is_offline)){ $query->andWhere(['o.is_offline' => $this->is_offline]); } if(!get_md_id() && isset($this->is_delivery)){ $query->andWhere(['o.is_delivery' => intval($this->is_delivery)]); } } if ($this->platform !== null && $this->platform !== '') { $query->andWhere([ 'o.order_origin' => $this->platform ]); } if($this->book_name){ $query->andWhere(['like', 'o.book_info', $this->book_name]); } if($this->book_mobile){ $query->andWhere(['like', 'o.book_info', $this->book_mobile]); } // 发货时间筛选 if($this->send_time){ $query->andWhere(['o.arrival_time' => strtotime($this->send_time)]); } $refundQuery1 = OrderRefund::find()->alias('or') ->select('or.status, or.order_id, or.created_at') ->where(['or.store_id' => $this->store_id, 'or.is_delete' => 0]); $refundQuery = (new Query())->from(['or' => $refundQuery1])->where('`or`.order_id=o.id') ->select('or.status') ->orderBy(['or.created_at' => SORT_DESC]) ->limit(1); if ($this->mobiles || $this->openids) { if($this->mobiles){ $_where = [ 'or', ['o.mobile' => $this->mobiles], ['u.binding' => $this->mobiles], ]; if($this->openids){ $_where[] = [ 'u.wechat_open_id' => $this->openids, ]; } }else{ $_where = [ 'u.wechat_open_id' => $this->openids, ]; } $query->andWhere($_where); } $query->orderBy('o.id DESC') ->addSelect(['o.*', 'u.nickname as de_name', 'u.platform', 'u.binding', 'u.avatar_url', 'refund' => $refundQuery, 'od.delivery_type', 'od.attr', 'o.name user_name', 'o.mobile user_mobile', 'o.address user_address', 'od.order_transit_id']); $query->addSelect($addSelect); $query->groupBy('o.id'); $sumQuery = clone $query; $sumPayPrice = $sumQuery->sum('pay_price'); $sumDailyQuery = clone $query; $sumDailyQuery->andWhere([ 'and', ['>=', 'o.created_at', strtotime(date('Y-m-d 00:00:00'))], ['<=', 'o.created_at', strtotime(date('Y-m-d 23:59:59'))], ]); $sumDaily = $sumDailyQuery->sum('pay_price'); $pagination = pagination_make($query); $listArray = $pagination['list']; if (isset($this->mch) && $this->mch == 1) { $mchList = (new MchForm(['store_id' => $this->store_id]))->mchSelectList(); $mchCommonCatSelectList = (new MchForm(['store_id' => get_store_id()]))->mchCommonCatSelectList(); } $store_delivery_time = (Option::get(OptionSetting::STORE_DELIVERY_TIME, $this->store_id, 0)['value']); if ($store_delivery_time) { $store_delivery_time = time() - ((int)$store_delivery_time * 86400); } foreach ($listArray as $i => &$item) { $item['is_store_delivery_time_out'] = $item['send_time'] < $store_delivery_time ? 1 : 0; if (isset($this->mch) && $this->mch == 1) { $item['mch'] = $mchList['data'][$item['mch_id']]; $item['mch_common_cat'] = $mchCommonCatSelectList['data'][$item['mch']['mch_common_cat_id']]; } $deliveryModel = DeliveryKeloop::findOne(['order_no' => $item['order_no']]); if($deliveryModel){ $delivery = $deliveryModel->attributes; $delivery['delivery_status_name'] = KeloopForm::$order_status_list[$delivery['delivery_status']] ?? ''; $item['delivery'] = $delivery; } $item['order_form'] = OrderForm::findAll(['order_id' => $item['id']]); if (get_md_id() > 0) { $md_profit = MdProfit::findOne(['order_id' => $item['id']]); $item['md_profit'] = [ 'sale_profit' => $md_profit->sale_profit ?: '0.00', 'pay_profit' => $md_profit->pay_profit ?: '0.00', 'clerk_profit' => $md_profit->clerk_profit ?: '0.00', 'total_profit' => $md_profit->total_profit ?: '0.00' ]; } $item['mobile'] = $item['mobile'] ?: $item['binding']; $item['book'] = []; if ($item['order_type'] == 1) { $attr = Json::decode($item['attr']); if (count($attr) > 1) { $date_data = current($attr)['date'] . '/' . end($attr)['date']; } else { $date_data = $attr[0]['date']; } $item['book'] = [ 'date' => $date_data ]; } $item['nickname'] = $item['de_name']; $item['avatar'] = $item['avatar_url']; if ($item['order_type'] == 2) { $tmp_attr = Json::decode($item['attr']); $item['book']['date'] = $tmp_attr['date'] . ' ' . $tmp_attr['time']; } $rmList = []; if ($this->order_id && $this->order_id > 0) { $rmQuery = \app\models\OrderRefundMoney::find()->where(['is_delete' => 0, 'order_id' => $this->order_id]); $rmList = $rmQuery->orderBy('id DESC')->asArray()->all(); foreach($rmList as &$k){ $k['created_at'] = date('Y-m-d H:i:s', $k['created_at']); } } $item['rmList'] = $rmList; if (!empty($item['food_flag_id'])) { $food_flag = FoodFlag::findOne($item['food_flag_id']); $item['food_table_num'] = $food_flag->table_num; } $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); $item['future_sales_time'] = $item['future_sales_time'] > 0 ? date('Y-m-d H:i:s', $item['future_sales_time']) : 0; $item['arrival_time_text'] = date('Y-m-d H:i:s', $item['arrival_time']); $item['goods_list'] = $this->getOrderGoodsList($item['id']); $item['clerk_name'] = ''; $shop = Shop::findOne($item['shop_id']); if ($shop) { $user = User::findOne(Shop::findOne($item['shop_id'])->user_id); if ($user) { $item['clerk_name'] = $user->nickname; } } $item['integral'] = json_decode($item['integral'], true); if (isset($item['address_data'])) { $item['address_data'] = json_decode($item['address_data']); } $item['flag'] = 0; $item['delivery_info'] = []; // 同城配送配送信息 if ($item['delivery_type'] == OrderDetail::GOODS_DELIVERY_IM) { $delivery_info = DeliveryInfo::findOne(['order_no' => $item['order_no']]); $item['delivery_info'] = [ 'waybill_id' => $delivery_info->waybill_id, 'status' => Delivery::$validOrderStatus[$delivery_info->status], 'reason' => $delivery_info->reason_id > 0 ? Delivery::$validReason[$delivery_info->reason_id] : '', 'fee' => $delivery_info->fee, 'duct_fee' => $delivery_info->deduct_fee, 'delivery_type' => Delivery::$deliveryType[$delivery_info->delivery_type], 'rider_name' => $delivery_info->rider_name, 'rider_mobile' => $delivery_info->rider_mobile ]; $item['delivery_time'] = date('Y-m-d H:i:s',$item['delivery_time']); } if($item['delivery_info']){ $item['pay_price'] > 0 && $item['express_price'] += $item['delivery_info']['fee']; // $item['pay_price'] > 0 && $item['total_price'] += $item['delivery_info']['fee']; // $item['pay_price'] > 0 && $item['pay_price'] += $item['delivery_info']['fee']; } $item['md_info'] = null; if ($item['md_id']) { $item['md_info'] = Md::find()->where(['id' => $item['md_id']]) ->select('id, name, address, cover_url, start_time, end_time, contact, mobile, open_status, shop_time_type, is_single, manager, cat_id')->asArray()->one(); $managerUser = SaasUser::findOne($item['md_info']['manager']); $item['md_info']['manager_name'] = $managerUser ? $managerUser->name : '-'; $item['md_info']['manager_mobile'] = $managerUser ? $managerUser->mobile : '-'; $mdCat = MdCategory::findOne($item['md_info']['cat_id']); $item['md_info']['md_cat_name'] = $mdCat ? $mdCat->name : '-'; } $item['pay_user_info'] = null; if ($item['pay_user_id'] > 0) { $pay_saas_user = SaasUser::findOne(['mobile' => User::findOne($item['pay_user_id'])->binding]); $item['pay_user_info'] = [ 'name' => $pay_saas_user->name, 'mobile' => $pay_saas_user->mobile ]; } $item['all_discount'] = sprintf("%.2f", ($item['integral']['forehead'] + $item['coupon_sub_price'])); $item['alipay_activity_voucher'] = AlipayAcitvityVoucherOrder::getByOrder($item['alipay_trade_no']); if ($item['store_id']) { // 增加查询商城的联系电话 $item['store'] = Store::find()->where(['id' => $item['store_id']])->select('id, name, province_id, city_id, district_id, address,contact_tel')->one(); } $diy_shop_name = Option::get(OptionSetting::DIY_SHOP_NAME, $item['store_id'], 'store', '自提配送')['value'] ?: '自提配送'; $diy_shop_name = Option::get(OptionSetting::DIY_SHOP_NAME, $item['store_id'], 'pay', $diy_shop_name)['value']; $diy_express_name = Option::get(OptionSetting::DIY_EXPRESS_NAME, $item['store_id'], 'store', '快递配送')['value'] ?: '快递配送'; $diy_express_name = Option::get(OptionSetting::DIY_EXPRESS_NAME, $item['store_id'], 'pay', $diy_express_name)['value']; $diy_delivery_name = Option::get(OptionSetting::DIY_DELIVERY_NAME, $item['store_id'], 'store', '同城配送')['value'] ?: '同城配送'; $diy_delivery_name = Option::get(OptionSetting::DIY_DELIVERY_NAME, $item['store_id'], 'pay', $diy_delivery_name)['value']; $item['diy_express_name'] = intval($item['is_offline']) === 1 ? $diy_shop_name : (intval($item['is_delivery']) === 1 ? $diy_delivery_name : $diy_express_name) ; if (empty($item['address']) && (int)$item['is_offline'] && !$item['mch_id']) { if (!empty($item['store'])) { $item['address'] = '配送到门店:' . $item['store']['name']; } if (!empty($item['md_info'])) { $item['address'] = '配送到门店:' . $item['md_info']['name']; } } // 单独查询一个订单的时候再处理这些数据 避免订单列表卡 if($this->order_id > 0){ $item['pay_type_name'] = Order::PAY_TYP_NAME[$item['pay_type']]; // 优惠明细 目前优惠有两种 优惠券优惠 和 积分抵扣 $item['discount_text'] = ''; if($item['integral']['forehead'] > 0 && $item['integral']['forehead_integral'] > 0){ $item['discount_text'] .= '使用'.$item['integral']['forehead_integral'].'积分抵扣'.$item['integral']['forehead'].'元;'; } if($item['coupon_sub_price'] > 0){ $item['discount_text'] .= '使用优惠券抵扣'.$item['coupon_sub_price'].'元;'; } // todo 小程序码和二维码 $filename = 'order_id_'.$item['id']; try { // if (!$this->order_id) { $scene = "id:{$item['id']},store:{$item['store_id']}"; $miniQrcode = ShareQrcode::wxQrcode('order/order-detail/order-detail', $scene); $item['qrcode'] = [ 'mini_qrcode'=>$miniQrcode['url_path'], 'qrcode' => str_replace('http://', 'http://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename. '.jpg') ]; //} } catch (\Exception $e) { $item['qrcode'] = [ 'mini_qrcode'=>'', 'qrcode' => '' ]; } $scene .= ",order_no:{$item['order_no']}"; $text = \Yii::$app->request->hostInfo . '/h5/#/order/order-detail/order-detail?scene=' . $scene; $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path); } //处理订单是否存在云仓转单商品开始 //添加转单详情 //一个订单一个供货商只能创建一次转单 // $transitInfo = OrderTransit::find()->where(['order_id'=>$item['id'],'is_delete'=>0])->all(); // if($transitInfo){ // $orderTransitInfo = []; // foreach($transitInfo as $transitInfoVal){ // $orderTransitInfo[] = $transitInfoVal->attributes; // } // $listArray[$i]['orderTransitInfo'] = $orderTransitInfo; // } // $verify_card = []; $item['is_front_delivery'] = 0; $integral = 0; foreach($item['goods_list'] as $goodskey=>&$goods_info){ if (isset($goods_info['is_front_delivery'])) { $item['is_front_delivery'] = $goods_info['is_front_delivery']; } $goods = Goods::findOne($goods_info['goods_id']); $warn_goods_timeout = Goods::warn_goods_timeout($item['store_id']); $goods_info['timeout_day'] = $goods->time_made_day ? date('Y-m-d', $goods->time_made_day + 86400 * $goods->time_shelf_life) : '--'; $goods_info['is_warn_goods_timeout'] = ($goods->time_made_day && ($goods->time_made_day + 86400 * $goods->time_shelf_life) < (time() + $warn_goods_timeout * 86400)) ? 1 : 0; if($goods_info['goods_id'] && $goods_info['attr']){ $goods_info['eipl'] = \app\models\ErpInventoryProp::logFind($item, $goods_info['goods_id'], json_decode($goods_info['attr'], true)); $cards = Goods::find()->where(['id' => $goods_info['goods_id']])->select('verify_card_id, integral')->one(); // if (!empty($cards->verify_card_id)) { // $goods_model = Goods::findOne($goods['goods_id']); // $ids = explode(',', $cards->verify_card_id); // $order = Order::findOne($item['id']); // $card = Tools::getVerifyList($ids, $order, $goods_model); // $verify_card = array_merge($verify_card, $card); // } if (!empty($cards->integral)) { $goods_integral = json_decode($cards->integral, true); $integral += (int)$goods_integral['give']; } if ((int)$item['is_pay'] !== 0 || intval($item['pay_type']) === 2) { $cloudGoodsInfo = CloudGoodsBind::find()->where(['goods_id' => $goods_info['goods_id'], 'is_delete' => 0])->one(); if ($cloudGoodsInfo && isset($cloudGoodsInfo['cloud_goods_id'])) { $cloudInfo = []; $cloudInfo['cloud_goods_id'] = $cloudGoodsInfo['cloud_goods_id']; $cloudInfo['cloud_attr_id'] = $cloudGoodsInfo['cloud_attr_id']; $cloudInfo['cloud_supplier_id'] = $cloudGoodsInfo['cloud_supplier_id']; if ($cloudGoodsInfo['cloud_supplier_id'] > 0) { $supplierInfo = Supplier::find()->select('name,logo')->where(['cloud_supplier_id' => $cloudGoodsInfo['cloud_supplier_id'], 'is_delete' => 0])->one(); if ($supplierInfo && $supplierInfo['name'] && $supplierInfo['logo']) { $cloudInfo['cloud_supplier_name'] = $supplierInfo['name']; $cloudInfo['cloud_supplier_logo'] = $supplierInfo['logo']; } } $listArray[$i]['goods_list'][$goodskey]['cloud_bind'] = json_encode($cloudInfo); if (intval($item['apply_delete']) === 0) { $listArray[$i]['is_cloud_bind'] = intval($item['trade_status']) === 0; } } } } } if ((int)$item['is_pay'] !== 0 || intval($item['pay_type']) === 2) { // $item['verify_card'] = $verify_card; $cards = []; if ($item['get_verify_id']) { $get_verify_id = explode(',', $item['get_verify_id']); $VerifyCardSale = VerifyCardSale::find()->alias('vcs')->where([ 'vcs.id' => $get_verify_id, ]) ->leftJoin(['vc' => VerifyCard::tableName()], 'vcs.verify_card_id = vc.id') ->leftJoin(['vca' => VerifyCardAccount::tableName()], 'vcs.account_id = vca.id') ->select('vca.account, vc.begin_time, vc.bg_pic_url, vc.business_status, vc.business_type, vc.content , vc.created_at, vc.date_type, vc.end_time, vc.expire_day, vc.freight_id, vcs.id, vc.is_business , vc.is_give, vc.money, vc.name, vc.num, vca.password, vc.pic_url, vc.price, vcs.id sale_id, vcs.status sale_status , vc.savingsType, vc.sort, vc.status, vc.total_num, vc.total_price, vc.type, vcs.use_num, vc.video_ids , vcs.video_status, vcs.goods_id')->asArray()->all(); if ($VerifyCardSale) { $cards = $VerifyCardSale; } } $item['verify_card'] = $cards; // $item['integral'] = $integral; } if($item['order_type'] == Order::ORDER_TYPE_WORKER){ $woe = WorkerOrderExt::findOne(['order_id' => $item['id']]); $item['woe'] = $woe; $item['w'] = $woe ? Worker::findOne($woe['worker_id']) : null; foreach($item['goods_list'] as &$good){ $wge = WorkerGoodsExt::findOne(['goods_id' => $good['goods_id']]); $good['wge'] = $wge; } } $item['givingGiftsOrderData'] = \app\modules\admin\models\givingGifts\GivingGiftsForm::givingGiftsOrderData($item); if ($arr['localPublicRanking'] == 1) { $item['LocalPublicRankingTask'] = LocalPublicRankingTask::findOne(['order_id' => $item['id']]); $item['LocalPublicRankingTask_parent'] = User::findOne($item['LocalPublicRankingTask']['parent_user_id']); } if($item['pt_order_id']){ $pt = \app\models\PtActivityOrder::findOne($item['pt_order_id']); if($pt->pt_number){ $item['pt_order_id'] = $pt->pt_number; } } if($item['confirm_time'] && !$item['send_time']){ $item['send_time'] = $item['confirm_time']; } /*新增是否是视频号小店订单的标识*/ $item['is_video_shop_order'] = VideoShopOrderExt::find()->where(['order_id' => $item['id']])->exists(); /*新增是否是视频号小店订单的标识*/ //获取退款的总商品金额 / 获取最新一条的状态 $handle_cancel = OrderGoodsCancel::find()->where(['order_id' => $item['id'], 'status' => [ OrderGoodsCancel::STATUS_APPLY, OrderGoodsCancel::STATUS_PAY_FAIL ]])->select('SUM(num) as num, SUM(refund_price) as refund_price')->groupBy('order_id')->asArray()->one() ?: null; $item['handle_cancel'] = $handle_cancel ?: null; $item['cancel_refund_price'] = OrderGoodsCancel::find()->where([ 'order_id' => $item['id'], 'status' => [ OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_PAY, OrderGoodsCancel::STATUS_PAY_FAIL ] ])->sum('refund_price') ?: 0; } // 获取可导出数据 $f = new ExportList(); $exportList = $f->getList(); if($this->export){ return $this->export($listArray); } //判断是否申请云仓 $is_cloud = false; if (\Yii::$app->isSaas()) { $store_cloud = StoreCloud::find()->where(['store_id' => get_store_id()])->one(); if ($store_cloud) { $is_cloud = true; } } //处理订单是否存在云仓转单商品结束 return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'mch_id'=>$this->mch_id, 'q' => $query->createCommand()->getRawSql(), 'sumPayPrice' => $sumPayPrice, 'sumDaily' => $sumDaily, 'export_list' => $exportList, 'express_list' => $this->getExpressList(), 'is_cloud' => $is_cloud, 'data' => $listArray, 'pageNo' => $pagination['pageNo'], 'pageSize' => $pagination['pageSize'], 'totalCount' => $pagination['totalCount'], 'print_setting' => Option::getPrintOrderSetting() ], ]; } private function export($list) { $rows = [[ 'ID', '会员信息', '订单号', '订单状态', '总金额(元)', '运费', '优惠金额', '实际支付(元)', '是否已付款', '快递名称', '快递单号', '快递状态', '收货人', '收货人电话', '收货人地址', '下单门店', '门店ID', '门店店长', '门店联系人', '门店店长联系方式', '门店分类', '商品', '规格', '数量', '成本价', '售价', '单价', '订单备注', '供货商信息', '时间', ]]; foreach($list as $item){ $tradStatus = ''; if($item['order_type'] == 1){ if(in_array($item['trade_status'], [0,2])){ $tradStatus = '待使用'; } } if ($item['trade_status'] == 1) { $tradStatus = '已取消'; } if ($item['is_pay'] == 0) { $tradStatus = '未支付'; } if ($item['is_pay'] == 1 && $item['trade_status']== 0) { $tradStatus = '待发货'; } if ($item['is_pay'] == 1 && $item['trade_status'] == 2) { $tradStatus = '待收货'; } if ($item['is_pay'] == 1 && $item['trade_status'] == 3) { $tradStatus = '已完成'; } $goods = []; $supplier_info = ''; $cost_price = 0; foreach ($item['goods_list'] as $i => $gitem) { $goods_info = json_decode($gitem['goods_info'], true); $goods_info || $goods_info = Goods::findOne($gitem['goods_id']); $supplier = Supplier::findOne(['cloud_supplier_id' => $goods_info['cloud_supplier_id']]); $supplier_info = $supplier->supplier_name; $attr = []; $order_attr = array_column($gitem['attr_list'], 'attr_id'); sort($order_attr); $goods_attr = json_decode($goods_info['attr'], true); $attr_cost_price = '0.00'; // $attr_goods_price = '0.00'; $attr_goods_price = $gitem['price']; foreach ($goods_attr as $value) { $goods_attr_id = array_column($value['attr_list'], 'attr_id'); sort($goods_attr_id); if (!array_diff($goods_attr_id, $order_attr)) { $attr_cost_price = $value['cost_price'] ?? $value['price']; // $attr_goods_price = $value['price'] ?: 0.00; } } $attr_cost_price = $attr_cost_price <= 0 ? '暂无数据' : sprintf('%.2f', $attr_cost_price); // $attr_goods_price = $attr_goods_price <= 0 ? '暂无数据' : sprintf('%.2f', $attr_goods_price); $cost_price = sprintf('%.2f', (doubleval($cost_price) + doubleval($attr_cost_price))); foreach ($gitem['attr_list'] as $atitem) { $attr[] = isset($atitem['attr_name']) ? $atitem['attr_name'] . isset($atitem['cost_price']) : ''; } $goods[] = $gitem['name'] . '(' . implode(',', $attr) . ')' . '(' . $gitem['num'] . $gitem['unit'] . ')' . '(' . $gitem['total_price'] . '元)(成本价:'.$attr_cost_price.')'; if($i == 0){ $r = [ $item['id'], $item['nickname'], $item['order_no'], $tradStatus, $item['total_price'], $item['express_price'], $item['all_discount'], $item['pay_price'], $item['is_pay'] ? '已付款' : '未付款', $item['express'], $item['express_no'], $item['status_text'], $item['name'], $item['mobile'], $item['address'], (($item['md_info'] && $item['md_info']['name']) ? $item['md_info']['name'] : '') . '-' . $item['store']['name'], ($item['md_info'] && $item['md_info']['id']) ? $item['md_info']['id'] : '-', ($item['md_info'] && $item['md_info']['manager_name']) ? $item['md_info']['manager_name'] : '-', ($item['md_info'] && $item['md_info']['contact']) ? $item['md_info']['contact'] : '-', ($item['md_info'] && $item['md_info']['mobile']) ? $item['md_info']['mobile'] : '-', ($item['md_info'] && $item['md_info']['md_cat_name']) ? $item['md_info']['md_cat_name'] : '-', $gitem['name'], implode(',', $attr), $gitem['num'] . $gitem['unit'], $attr_cost_price, $attr_goods_price, $gitem['single_price'], $item['remark'], $supplier_info, $item['created_at'], ]; $rows[] = $r; }else{ $r = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', $gitem['name'], implode(',', $attr), $gitem['num'] . $gitem['unit'], $attr_cost_price, $attr_goods_price, $gitem['single_price'], '', $supplier_info, '', ]; $rows[] = $r; } } } $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow() ->addRows($rows)->toBrowser(); } //获取快递信息 public function getExpressData() { try { $order_id = $this->order_id; $order = Order::find()->where(['id' => $order_id, 'is_pay' => 1])->one(); if ($order) { // $OrderTransit = OrderTransit::findOne(['order_id' => $order->id]); // if ($OrderTransit) { // $order['express_name'] = $OrderTransit->express_name; // $order['express_no'] = $OrderTransit->express_no; // } } if (!empty($order['express']) && !empty($order['express_no'])) { // 查询物流信息 $model = new ExpressDetail(); $model->express = $order['express']; $model->express_no = $order['express_no']; $model->receive_mobile = $order['mobile']; $model->store_id = $order->store_id == 0 ? 1 : $this->store_id; $res = $model->search(); if ($res['code'] != 0) { $res['code'] = 0; if (!$res['data']) { $res['data'] = []; } $res['data']['status'] = 0; $res['data']['status_text'] = '未知'; } $res['data']['express'] = $order['express']; $res['data']['express_no'] = $order['express_no']; return $res; } return [ 'code' => 0, 'msg' => "没有快递信息", 'data' => null ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * @param $data array 需要处理的数据 */ public function dataTransform($data) { //TODO 测试数据 需要换成真实的字段 $newFields = []; foreach ($this->fields as &$item) { if ($this->is_offline == 1) { if (in_array($item['key'], ['clerk_name', 'shop_name'])) { $item['selected'] = 1; } } else { if (in_array($item['key'], ['express_price', 'express_no', 'express'])) { $item['selected'] = 1; } } if (isset($item['selected']) && $item['selected'] == 1) { $newFields[$item['key']] = $item['value']; } } $newList = []; foreach ($data as $datum) { $newItem = []; $newItem['order_no'] = $datum->order_no; $newItem['nickname'] = $datum->user->nickname; $newItem['name'] = $datum->name; $newItem['mobile'] = $datum->mobile; $newItem['address'] = $datum->address; $newItem['total_price'] = $datum->total_price; $newItem['pay_price'] = $datum->pay_price; $newItem['pay_time'] = $datum->pay_time ? date('Y-m-d H:i', $datum->pay_time) : ''; $newItem['send_time'] = $datum->send_time ? date('Y-m-d H:i', $datum->send_time) : ''; $newItem['confirm_time'] = $datum->confirm_time ? date('Y-m-d H:i', $datum->confirm_time) : ''; $newItem['words'] = $datum->words; $newItem['goods_list'] = $this->getOrderGoodsList($datum['id']); $newItem['is_pay'] = $datum['is_pay'] == 1 ? "已付款" : "未付款"; $newItem['addtime'] = date('Y-m-d H:i', $datum['created_at']); $newItem['express_price'] = $datum['express_price'] . "元"; $newItem['apply_delete'] = ($datum['apply_delete'] == Order::ORDER_APPLY_DELETE) ? ($datum['trade_status'] == Order::ORDER_FLOW_CANCEL || $datum['is_delete'] == Order::IS_DELETE_TRUE ? '取消成功' : '取消中') : "无"; $newItem['trade_status'] = OrderStateFlow::getFlowWords($datum['trade_status']); // 是否到店自提 0--否 1--是 if ($datum['is_offline']) { $newItem['clerk_name'] = $datum->clerk ? $datum->clerk->nickname : ''; $newItem['shop_name'] = $datum->shop ? $datum->shop->name : ''; } else { $newItem['express_price'] = $datum->express_price; $newItem['express_no'] = $datum->express_no; $newItem['express'] = $datum->express; } if ($datum->orderForm) { $str = ''; foreach ($datum->orderForm as $key => $item) { $str .= $item['key'] . ':' . $item['value'] . ','; } $newItem['content'] = rtrim($str, ','); } else { $newItem['content'] = $datum->content; } $newList[] = $newItem; } //Export::order_3($newList, $newFields); } public function getOrderGoodsList($order_id, $order_detail_id = 0) { $order = Order::findOne($order_id); $query = OrderDetail::find()->alias('od') ->leftJoin(['g' => Goods::tableName()], 'od.goods_id = g.id') ->leftJoin(['wh' => Warehouse::tableName()], 'wh.id = g.warehouse_id') ->leftJoin(['whz' => WarehouseZone::tableName()], 'whz.id = g.warehouse_zone_id') ->where([ 'od.is_delete' => 0, 'od.order_id' => $order_id, ]); if ($order_detail_id) { $query->andWhere(['od.id' => $order_detail_id]); } $orderDetailList = $query->select(['od.num', 'od.total_price', 'g.goods_no', 'g.time_made_day', 'g.time_shelf_life', 'od.attr', 'od.food_ext_goods', 'od.is_level', 'od.batch_price_tips', 'name' => 'od.goods_name','od.pic', 'od.goods_info', 'od.delivery_type', 'od.shop_id', 'od.goods_id', 'g.attr attrs','wh.name as wh_name','whz.name as whz_name', 'g.is_front_delivery', 'order_detail_id' => 'od.id'])->asArray()->all(); foreach ($orderDetailList as &$item) { //获取已经取消多少件 $cancel_num = OrderGoodsCancel::getCancelGoodsOrderQuery( $order_id, 'SUM(num)', 'order_detail_id', $item['order_detail_id'])->scalar() ?: 0; //获取可取消数量 $item['max_cancel_num'] = bcsub($item['num'], $cancel_num); //如果是营销活动产品就不给取消 if (!OrderGoodsCancel::is_activity_goods($order_id, $item['goods_id'])) { $item['max_cancel_num'] = 0; } // if (intval($order->trade_status) !== \app\models\Order::ORDER_FLOW_NO_SEND) { // $item['max_cancel_num'] = 0; // } if (intval($order->is_sale) || ($order->future_sales_time > 0 && $order->future_sales_time <= time())) { $item['max_cancel_num'] = 0; } $item['cancel_num'] = OrderGoodsCancel::find()->where([ 'order_detail_id' => $item['order_detail_id'], 'status' => [ OrderGoodsCancel::STATUS_PAY, OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_PAY_FAIL ] ])->sum('num') ?: 0; $item['cancel_status'] = 0; $item['cancel_text'] = ''; if ($item['cancel_num'] > 0) { $item['cancel_text'] = '已退款' .$item['cancel_num'] .'件'; $item['cancel_status'] = 2; if ($item['cancel_num'] >= $item['num']) { $item['cancel_status'] = 1; $item['cancel_text'] = '已退款'; } } $item['warehouse_name'] = $item['wh_name'].'-'.$item['whz_name']; $item['form'] = OrderForm::findAll(['goods_id' => $item['goods_id'], 'order_id' => $order_id]); $item['food_ext_goods'] = (array)json_decode($item['food_ext_goods'], true); $item['attr_list'] = json_decode($item['attr'], true); $item['unit'] = Json::decode($item['goods_info'])['unit']; // $item['price'] = sprintf('%.2f', ($item['total_price'] / $item['num'])); $item['price'] = $item['total_price'] > 0 ? sprintf('%.2f', ($item['total_price'] / $item['num'])) : $item['total_price']; $item['is_front_delivery'] = intval($item['is_front_delivery']); // $item['attrs'] = json_decode($item['attrs'], true); // $attr_id = array_column($item['attr_list'], 'attr_id'); // sort($attr_id); // foreach ($item['attrs'] as $attr) { // $attr_item_id = array_column($attr['attr_list'], 'attr_id'); // sort($attr_item_id); // if (!array_diff($attr_item_id, $attr_id)) { // $item['price'] = $attr['price']; // break; // } // } $oattr = json_decode($item['attr'], true); $oattrIds = array_column($oattr, 'attr_id'); sort($oattrIds); $gattr = json_decode($item['goods_info'], true)['attr']; $gattr = json_decode($gattr, true); $goods_no = ''; $item['single_price'] = $item['price']; $item['goods_no'] = trim($goods_no ?: $item['goods_no']); $item['code_path'] = ''; if ($item['goods_no']) { $generator = new BarcodeGeneratorJPG(); $barcode = $generator->getBarcode($item['goods_no'], $generator::TYPE_CODE_128, 2, 30); $filename = md5('goods_no_' . $item['goods_no']); $code_path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); file_put_contents($code_path, $barcode); $item['code_path'] = $pic_url; } $item['shop'] = []; if ($item['delivery_type'] == OrderDetail::GOODS_DELIVERY_SHOP) { $shop_info = Shop::find()->where(['id' => $item['shop_id']])->asArray()->one(); if(!$shop_info) continue; $item['shop']['address'] = $shop_info['address']; $item['shop']['id'] = $shop_info['id']; $item['shop']['name'] = $shop_info['name']; $item['shop']['mobile'] = $shop_info['mobile']; } } return $orderDetailList; } public static function getCountData($store_id) { $form = new OrderListForm(); $form->limit = 0; $form->store_id = $store_id; $data = []; $form->status = -1; $res = $form->search(); $data['all'] = $res['row_count']; $form->status = 0; $res = $form->search(); $data['status_0'] = $res['row_count']; $form->status = 1; $res = $form->search(); $data['status_1'] = $res['row_count']; $form->status = 2; $res = $form->search(); $data['status_2'] = $res['row_count']; $form->status = 3; $res = $form->search(); $data['status_3'] = $res['row_count']; $form->status = 5; $res = $form->search(); $data['status_5'] = $res['row_count']; return $data; } /** * @return array */ public function getExpressList() { // $storeExpressList = Order::find() // ->select('express') // ->where([ // 'and', // ['store_id' => $this->store_id], // ['is_pay' => Order::IS_PAY_TRUE], // ['in', 'trade_status', [Order::ORDER_FLOW_SEND, Order::ORDER_FLOW_CONFIRM]], // ['!=', 'express', ''], // ])->groupBy('express, send_time')->orderBy('send_time DESC')->limit(5)->asArray()->all(); $expressLst = Express::getExpressList(); // $newStoreExpressList = []; // foreach ($storeExpressList as $i => $item) { // foreach ($expressLst as $value) { // if ($value['name'] == $item['express']) { // $newStoreExpressList[] = $item['express']; // break; // } // } // } $newPublicExpressList = []; foreach ($expressLst as $i => $item) { $newPublicExpressList[] = $item['name']; } return $newPublicExpressList; } public function orderGoodsCancelList() { $status = $this->status; $order_no = $this->order_no; $goods_name = $this->goods_name; $mobile = $this->mobile; $dateStart = $this->dateStart; $dateEnd = $this->dateEnd; $md_name = $this->md_name; $order_type = $this->order_type; $platform = $this->platform; $user_name = $this->user_name; $name = $this->name; // $activity_type = $this->activity_type; $province_id = $this->province_id; $district_id = $this->district_id; $city_id = $this->city_id; $cat_id = $this->cat_id; $query = OrderGoodsCancel::find()->alias('ogc') ->leftJoin(['o' => Order::tableName()], 'ogc.order_id = o.id') ->leftJoin(['u' => User::tableName()], 'o.user_id = u.id') ->leftJoin(['od' => OrderDetail::tableName()], 'ogc.order_detail_id = od.id') ->where(['IS NOT', 'o.id', null]); if (isset($status) && in_array($status, [ OrderGoodsCancel::STATUS_APPLY, OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_REFUSE, ])) { if (intval($status) === OrderGoodsCancel::STATUS_APPLY) { $query->andWhere(['ogc.status' => [ OrderGoodsCancel::STATUS_APPLY, OrderGoodsCancel::STATUS_PAY_FAIL ]]); } elseif (intval($status) === OrderGoodsCancel::STATUS_PASS) { $query->andWhere(['ogc.status' => [ OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_PAY ]]); } else { $query->andWhere(['ogc.status' => [ OrderGoodsCancel::STATUS_REFUSE, OrderGoodsCancel::STATUS_CANCEL ]]); } } if (trim($order_no)) { $query->andWhere(['LIKE', 'o.order_no', trim($order_no)]); } if (trim($goods_name)) { $query->andWhere(['LIKE', 'od.goods_name', trim($goods_name)]); } if (trim($mobile)) { $query->andWhere(['OR', ['LIKE', 'o.mobile', $mobile], ['LIKE', 'u.binding', $mobile]]); } if ($dateStart) { $dateStart = strtotime($dateStart); $query->andWhere(['>=', 'o.created_at', $dateStart]); } if ($dateEnd) { $dateEnd = strtotime($dateEnd); $query->andWhere(['<=', 'o.created_at', $dateEnd]); } if ($md_name) { $query->leftJoin(['md' => Md::tableName()], 'md.id=o.md_id') ->andWhere(['like', 'md.name', $md_name]); } if (isset($order_type) && in_array($order_type, [0, 1, 2, 3, Order::ORDER_TYPE_WORKER, Order::ORDER_TYPE_INTEGRAL])) { $query->andWhere([ 'o.order_type' => $this->order_type ]); } if (!empty($platform)) { $query->andWhere([ 'o.order_origin' => $this->platform ]); } //用户昵称 if ($user_name) { $query->andWhere([ 'LIKE', 'u.nickname', $user_name ]); } //收货人 if ($name) { $query->andWhere([ 'LIKE', 'o.name', $name ]); } if (!empty($province_id)) { $query->andWhere(['o.province_id' => $province_id]); } if (!empty($city_id)) { $query->andWhere(['o.city_id' => $city_id]); } if (!empty($district_id)) { $query->andWhere(['o.district_id' => $district_id]); } if($cat_id > 0){ // 获取所有绑定这个分类ID的商品ID $goodsID = GoodsCat::find()->where(['is_delete' => 0, 'cat_id' => $cat_id])->select('goods_id')->column(); if(!empty($goodsID)){ $query->andWhere(['od.goods_id' => $goodsID]); } } $refundQuery1 = OrderRefund::find()->alias('or') ->select('or.status, or.order_id, or.created_at') ->where(['or.store_id' => $this->store_id, 'or.is_delete' => 0]); $refundQuery = (new Query())->from(['or' => $refundQuery1])->where('`or`.order_id=o.id') ->select('or.status') ->orderBy(['or.created_at' => SORT_DESC]) ->limit(1); $query->groupBy('ogc.id')->orderBy('ogc.created_at desc')->select([ 'o.store_id', 'o.user_id', 'o.saas_id', 'o.order_no', 'o.pay_price', 'o.balance', 'o.arrival_time', 'o.express_price', 'o.name', 'o.mobile', 'o.address', 'o.remark', 'o.is_pay', 'o.pay_type', 'o.pay_time', 'o.send_time', 'o.express', 'o.express_no', 'o.confirm_time', 'o.apply_delete', 'o.is_delete', 'o.coupon_sub_price', 'o.is_offline', 'o.words', 'o.rebate', 'o.seller_comments', 'o.mch_id', 'o.order_origin', 'o.is_recycle', 'o.supplier_id', 'o.trade_status', 'o.combine_money', 'o.order_type', 'o.book_info', 'o.is_delivery', 'o.delivery_time', 'o.md_id', 'o.is_trans', 'o.food_book_ext', 'o.pay_user_id', 'o.food_flag_id', 'o.food_code', 'o.get_verify_id', 'o.trans_status', 'o.trans_error', 'o.rand_discount', 'o.id as order_id', 'o.integral', 'o.give_integral' ])->addSelect(['u.nickname', 'u.platform', 'u.binding', 'u.avatar_url as avatar', 'refund' => $refundQuery, 'od.delivery_type', 'od.attr', 'o.name user_name', 'o.mobile user_mobile', 'o.address user_address', 'od.order_transit_id', 'ogc.status', 'ogc.id as cancel_order_id', 'ogc.refund_price as cancel_refund_price', 'ogc.num as cancel_num', 'ogc.order_detail_id as cancel_order_detail_id', 'ogc.created_at']); $list = pagination_make($query); foreach ($list['list'] as &$item) { if (!empty($item['food_flag_id'])) { $food_flag = FoodFlag::findOne($item['food_flag_id']); $item['food_table_num'] = $food_flag->table_num; } $item['status'] = intval($item['status']); $item['status_text'] = OrderGoodsCancel::$status_text[$item['status']]; if ($item['status'] === OrderGoodsCancel::STATUS_PAY) { $item['status'] = 1; } if ($item['status'] === OrderGoodsCancel::STATUS_PAY_FAIL) { $item['status'] = 0; } if ($item['status'] === OrderGoodsCancel::STATUS_CANCEL) { $item['status'] = 2; } $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); $item['goods_list'] = $this->getOrderGoodsList($item['order_id'], $item['cancel_order_detail_id']); $item['md_info'] = null; if ($item['md_id']) { $item['md_info'] = Md::find()->where(['id' => $item['md_id']]) ->select('id, name, address, cover_url, start_time, end_time, contact, mobile, open_status, shop_time_type, is_single, manager, cat_id')->asArray()->one(); $managerUser = SaasUser::findOne($item['md_info']['manager']); $item['md_info']['manager_name'] = $managerUser ? $managerUser->name : '-'; $item['md_info']['manager_mobile'] = $managerUser ? $managerUser->mobile : '-'; $mdCat = MdCategory::findOne($item['md_info']['cat_id']); $item['md_info']['md_cat_name'] = $mdCat ? $mdCat->name : '-'; } $item['pay_user_info'] = null; if ($item['pay_user_id'] > 0) { $pay_saas_user = SaasUser::findOne(['mobile' => User::findOne($item['pay_user_id'])->binding]); $item['pay_user_info'] = [ 'name' => $pay_saas_user->name, 'mobile' => $pay_saas_user->mobile ]; } $item['integral'] = json_decode($item['integral'], true); $item['all_discount'] = sprintf("%.2f", ($item['integral']['forehead'] + $item['coupon_sub_price'])); if ($item['store_id']) { // 增加查询商城的联系电话 $item['store'] = Store::find()->where(['id' => $item['store_id']])->select('id, name, province_id, city_id, district_id, address,contact_tel')->one(); } $diy_shop_name = Option::get(OptionSetting::DIY_SHOP_NAME, $item['store_id'], 'store', '自提配送')['value'] ?: '自提配送'; $diy_shop_name = Option::get(OptionSetting::DIY_SHOP_NAME, $item['store_id'], 'pay', $diy_shop_name)['value']; $diy_express_name = Option::get(OptionSetting::DIY_EXPRESS_NAME, $item['store_id'], 'store', '快递配送')['value'] ?: '快递配送'; $diy_express_name = Option::get(OptionSetting::DIY_EXPRESS_NAME, $item['store_id'], 'pay', $diy_express_name)['value']; $diy_delivery_name = Option::get(OptionSetting::DIY_DELIVERY_NAME, $item['store_id'], 'store', '同城配送')['value'] ?: '同城配送'; $diy_delivery_name = Option::get(OptionSetting::DIY_DELIVERY_NAME, $item['store_id'], 'pay', $diy_delivery_name)['value']; $item['diy_express_name'] = intval($item['is_offline']) === 1 ? $diy_shop_name : (intval($item['is_delivery']) === 1 ? $diy_delivery_name : $diy_express_name) ; if (empty($item['address']) && (int)$item['is_offline'] && !$item['mch_id']) { if (!empty($item['store'])) { $item['address'] = '配送到门店:' . $item['store']['name']; } if (!empty($item['md_info'])) { $item['address'] = '配送到门店:' . $item['md_info']['name']; } } if($this->order_id > 0){ $item['pay_type_name'] = Order::PAY_TYP_NAME[$item['pay_type']]; // 优惠明细 目前优惠有两种 优惠券优惠 和 积分抵扣 $item['discount_text'] = ''; if($item['integral']['forehead'] > 0 && $item['integral']['forehead_integral'] > 0){ $item['discount_text'] .= '使用'.$item['integral']['forehead_integral'].'积分抵扣'.$item['integral']['forehead'].'元;'; } if($item['coupon_sub_price'] > 0){ $item['discount_text'] .= '使用优惠券抵扣'.$item['coupon_sub_price'].'元;'; } } $item['is_front_delivery'] = 0; $integral = 0; foreach($item['goods_list'] as $goodskey=>&$goods_info){ if (isset($goods_info['is_front_delivery'])) { $item['is_front_delivery'] = $goods_info['is_front_delivery']; } $goods_info['num'] = $item['cancel_num']; $goods_info['total_price'] = $item['cancel_refund_price']; } if ((int)$item['is_pay'] !== 0 || intval($item['pay_type']) === 2) { // $item['verify_card'] = $verify_card; $cards = []; if ($item['get_verify_id']) { $get_verify_id = explode(',', $item['get_verify_id']); $VerifyCardSale = VerifyCardSale::find()->alias('vcs')->where([ 'vcs.id' => $get_verify_id, ]) ->leftJoin(['vc' => VerifyCard::tableName()], 'vcs.verify_card_id = vc.id') ->leftJoin(['vca' => VerifyCardAccount::tableName()], 'vcs.account_id = vca.id') ->select('vca.account, vc.begin_time, vc.bg_pic_url, vc.business_status, vc.business_type, vc.content , vc.created_at, vc.date_type, vc.end_time, vc.expire_day, vc.freight_id, vcs.id, vc.is_business , vc.is_give, vc.money, vc.name, vc.num, vca.password, vc.pic_url, vc.price, vcs.id sale_id, vcs.status sale_status , vc.savingsType, vc.sort, vc.status, vc.total_num, vc.total_price, vc.type, vcs.use_num, vc.video_ids , vcs.video_status, vcs.goods_id')->asArray()->all(); if ($VerifyCardSale) { $cards = $VerifyCardSale; } } $item['verify_card'] = $cards; // $item['integral'] = $integral; } if($item['confirm_time'] && !$item['send_time']){ $item['send_time'] = $item['confirm_time']; } } $f = new ExportList(); $exportList = $f->getList(); if($this->export){ return $this->export($list['list']); } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'export_list' => $exportList, // 'express_list' => $this->getExpressList(), 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'pageSize' => $list['pageSize'], 'totalCount' => $list['totalCount'], 'print_setting' => Option::getPrintOrderSetting() ], ]; } }