-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_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'], 'safe'], [['keloop', 'keloop_delivery_status'], 'safe'], [['status_ext', 'worker_name', 'worker_tel'], 'safe'], [['booking_time_start', 'booking_time_end', 'worker_id', 'is_wastore'], 'safe'], ['cat_id', 'integer'], ['cat_id', 'default', 'value' => 0] ]; } public function search() { 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]); $query->andWhere(['o.store_id' => $this->store_id]); if (!empty($this->selected_row_keys)) { $query->andWhere(['in', 'o.id', $this->selected_row_keys]); } 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 (get_md_id()) { $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 ]); } if (!empty($this->pay_type) && in_array($this->pay_type, [0, 1, 2, 3, 4, 5, 6, 11])) { $query->andWhere([ 'o.pay_type' => $this->pay_type ]); } $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; default: // 如果$order_id`为空,只过滤未删除的订单 if (empty($this->order_id)) { $query->andWhere([ 'o.is_delete' => Order::IS_DELETE_FALSE ]); } break; } if ($this->order_id && $this->order_id > 0) { $query->andWhere(['o.id' => $this->order_id]); } if (!$this->order_id) { 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(['like', 'u.nickname', $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)]); } 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->platform !== null && $this->platform !== '') { $query->andWhere([ 'u.platform' => $this->platform ]); } if (!empty($this->filters_is_pay)) { $query->andWhere(['o.is_pay' => $this->filters_is_pay]); } if (!empty($this->filters_order_types)) { foreach ($this->filters_order_types as $key => $value) { if ($value == 0) { $query->andWhere(['o.is_offline' => 0]); } if ($value == 1) { $query->andWhere(['o.is_offline' => 1]); } if ($value == 2) { $query->andWhere(['o.is_delivery' => 1]); } if ($value == 3) { $query->andWhere(['o.order_origin' => 4]); } } } $query->leftJoin(['a' => Admin::tableName()], 'a.id= o.admin_id '); $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') ->select([ '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', 'a.name admin_name' ]); $query->addSelect($addSelect); $query->groupBy('o.id'); if (!empty($this->sort) && !empty($this->sort_type)) { if ($this->sort_type == 'id') { $query->orderBy(['o.id' => $this->sort == 'asc' ? SORT_ASC : SORT_DESC,]); } if ($this->sort_type == 'sort') { $query->orderBy(['o.sort' => $this->sort == 'asc' ? SORT_ASC : SORT_DESC,]); } if ($this->sort_type == 'total_price') { $query->orderBy(['o.total_price' => $this->sort == 'asc' ? SORT_ASC : SORT_DESC,]); } if ($this->sort_type == 'pay_price') { $query->orderBy(['o.pay_price' => $this->sort == 'asc' ? SORT_ASC : SORT_DESC,]); } if ($this->sort_type == 'pay_datetime') { $query->orderBy(['o.pay_time' => $this->sort == 'asc' ? SORT_ASC : SORT_DESC,]); } } else { $query->orderBy(['o.id' => SORT_DESC]); } $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']; foreach ($listArray as $i => &$item) { if ($item['order_origin'] == 4) { $item['order_types'] = 3; } else if ($item['is_delivery'] == 1) { $item['order_types'] = 2; } else if ($item['is_offline'] == 1) { $item['order_types'] = 1; } else if ($item['is_offline'] == 0) { $item['order_types'] = 0; } $item['pay_datetime'] = date('Y-m-d H:i:s', $item['created_at']);; $item['goods_list'] = $this->getOrderGoodsList($item['id']); $item['avatar'] = ''; if (empty($item['binding'])) { $item['nickname'] = $item['de_name']; $item['avatar'] = $item['avatar_url']; } else { $sass_user = SaasUser::findOne(['mobile' => $item['binding']]); if ($sass_user) { $item['nickname'] = $sass_user->name; $item['avatar'] = $sass_user->avatar; } } 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['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 ]; } if ($item['delivery_info']) { $item['pay_price'] > 0 && $item['express_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, mobile, open_status, shop_time_type, is_single')->one(); } $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']) { if (!empty($item['store'])) { $item['address'] = '配送到门店:' . $item['store']['name']; } if (!empty($item['md_info'])) { $item['address'] = '配送到门店:' . $item['md_info']['name']; } } $integral = 0; if ((int)$item['is_pay'] !== 0) { foreach ($item['goods_list'] as $goodskey => &$goods) { if ($goods['goods_id'] && $goods['attr']) { $cards = Goods::find()->where(['id' => $goods['goods_id']])->select('verify_card_id, integral')->one(); if (!empty($cards->integral)) { $goods_integral = json_decode($cards->integral, true); $integral += (int)$goods_integral['give']; } $cloudGoodsInfo = CloudGoodsBind::find()->where(['goods_id' => $goods['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); $listArray[$i]['is_cloud_bind'] = (int)$item['trade_status'] === 0; } } } $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; } } 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']; } } $adminPermission = AdminRole::find()->alias('ar') ->leftJoin(['ad' => AuthRole::tableName()], 'ad.id=ar.role_id') ->select(['ad.edit_data', 'ar.admin_id']) ->asArray() ->all(); $has_admin = false; foreach ($adminPermission as $permission) { $data = json_decode($permission['edit_data'], true); if (in_array('PaymentStatement', (array)$data)) { $admins = Admin::find() ->where([ 'or', ['id' => $permission['admin_id']], ['and', ['type' => ['admin', 'staff']], ['is_delete' => 0]] ]) ->all(); foreach ($admins as $admin) { if ($admin->id == $this->admin->id) { $has_admin = true; break; } } } } // 获取可导出数据 $f = new ExportList(); $exportList = $f->getList(); if ($this->export) { return $this->export($listArray); } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'q' => $query->createCommand()->getRawSql(), 'totalSum' => $sumPayPrice, 'has_admin' => $has_admin, 'admins' => $admins ?? [], 'admin' => $this->admin, 'sumDaily' => $sumDaily, 'export_list' => $exportList, 'data' => $listArray, 'pageNo' => $pagination['pageNo'], 'pageSize' => $pagination['pageSize'], 'totalCount' => $pagination['totalCount'], 'print_setting' => Option::getPrintOrderSetting() ], ]; } private function export($list) { $rows = [[ 'ID', '排单', '会员信息', '订单号', '订单状态', '总金额(元)', '运费', '实际支付(元)', '是否已付款', '收货人', '收货人电话', '收货人地址', '下单门店', '商品', '规格', '数量', '成本价', '售价', '供货商信息', '备注', '时间', ]]; usort($list, function ($a, $b) { if ($a['sort'] == 0 && $b['sort'] == 0) { return 0; } if ($a['sort'] == 0) { return 1; } if ($b['sort'] == 0) { return -1; } return $a['sort'] <=> $b['sort']; }); 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'; 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 . ')'; $dateString = date('Y-m-d H:i:s', $item['created_at']); if ($i == 0) { $r = [ $item['id'], $item['sort'], $item['nickname'], $item['order_no'], $tradStatus, $item['total_price'], $item['express_price'], $item['pay_price'], $item['is_pay'] ? '已付款' : '未付款', $item['name'], $item['mobile'], $item['address'], (($item['md_info'] && $item['md_info']['name']) ? $item['md_info']['name'] : '') . '-' . $item['store']['name'], $gitem['name'], implode(',', $attr), $gitem['num'] . $gitem['unit'], $attr_cost_price, $attr_goods_price, $supplier_info, $item['shop_remark'], $item['created_at'], ]; $rows[] = $r; } else { $r = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', $gitem['name'], implode(',', $attr), $gitem['num'] . $gitem['unit'], $attr_cost_price, $attr_goods_price, $supplier_info, '', ]; $rows[] = $r; } } } $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow() ->addRows($rows)->toBrowser(); } public function getOrderGoodsList($order_id) { $orderDetailList = OrderDetail::find()->alias('od') ->leftJoin(['g' => Goods::tableName()], 'od.goods_id = g.id') ->where([ 'od.is_delete' => 0, 'od.order_id' => $order_id, ])->select(['od.num', 'od.total_price', 'g.goods_no', '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'])->asArray()->all(); foreach ($orderDetailList as &$item) { $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'])); $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 = ''; foreach ($gattr as $igattr) { $attrIds = array_column($igattr['attr_list'], 'attr_id'); sort($attrIds); if (implode('_', $attrIds) === implode('_', $oattrIds)) { $goods_no = $igattr['no']; } } $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 function confirmPayment() { if (!empty($this->confirm_payment) && !empty($this->change_admin_id)) { Order::updateAll(['confirm_payment' => 1, 'is_pay' => 1, 'admin_id' => $this->change_admin_id], ['id' => $this->confirm_payment]); } $admin = Admin::findOne($this->change_admin_id); return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'admin_name' => $admin->name ], ]; } }