_filter_mch_list(); if($this->hasErrors()){ return [ 'code' => 1, 'msg' => array_shift($this->getFirstErrors()), ]; } return [ 'code' => 0, 'data' => $mch_list, ]; } public function search() { if (!$this->validate()) return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; // HKG 新增判断商城打烊状态 开始 if(Option::get(OptionSetting::MALL_STATUS,get_store_id(),'store',0)['value'] == 1) return [ 'code' => 1, 'msg' => '商城已打烊~' ]; // HKG 新增判断商城打烊状态 结束 try { // 预生成订单号 //$order_no = OrderNo::getOrderNo(OrderNo::ORDER_MALL); // cache()->set('delivery_order_no_' . get_user_id(), $order_no); $mchList = $this->getMchListData(); if (isset($mchList['code']) && $mchList['code'] === 1) { return $mchList; } $agreement_id = 0; $agreement_title = ''; $adopt_order = false; foreach ($mchList as &$mch) { $order_no = OrderNo::getOrderNo(OrderNo::ORDER_MALL); $goods_id = array_column($mch['goods_list'], 'goods_id'); if ((!empty(input_params('flag_id')) || !empty(input_params('table_num')))) { $order_no = OrderNo::getOrderNo(OrderNo::ORDER_ALIPAY_FOOD); foreach($mch['goods_list'] as $uitem){ $goods_id = array_unique(array_merge($goods_id, array_column($uitem['goods_list'], 'goods_id'))); } } if ($mch['goods_list'][0]['product_type'] == Goods::GOODS_TYPE_ADOPT) { $adopt_order = true; } sort($goods_id); $goods_id = implode(',', $goods_id); $goods_id = md5($goods_id); cache()->set('delivery_order_no_' . $goods_id . '_' . get_user_id(), $order_no); } // var_dump(json_encode($mchList));die; if(isset($mchList['code']) && $mchList['code'] == 1){ return $mchList; } if ($adopt_order) { $adoptSetting = AdoptSetting::findOne(['store_id' => $this->store_id]); $agreement_id = $adoptSetting->agreement_id; $agreement_title = AboutArticle::find()->where([ 'is_delete' => 0, 'id' => $adoptSetting->agreement_id, ])->select('name')->scalar() ?: '认养协议'; } } catch(\Exception $e) { return [ 'code' => 1, 'line' => $e->getLine(), 'msg' => $e->getMessage(), 'file' => $e->getFile(), ]; } $food_pay_type = []; $md_info = []; $flag_id = 0; $tableInfo = []; $store = Store::findOne(get_store_id()); $mchModel = Mch::findOne(get_mch_id()); $md = Md::findOne(get_md_id()); $food_pay_list = []; if (get_md_id() && (!empty(input_params('flag_id')) || !empty(input_params('table_num')))) { if (!empty(input_params('flag_id'))) { $flagInfo = FoodFlag::findOne(['id' => input_params('flag_id')]); } else { $flagInfo = FoodFlag::findOne(['store_id' => get_store_id(), 'md_id' => get_md_id(), 'status' => 0, 'table_num' => input_params('table_num')]); } $flag_id = $flagInfo->id; $flagType = $flagInfo->type; // 根据桌号 查询 $tableInfo = FoodTableNumber::find()->where(['num' => $flagInfo->table_num,'store_id' => get_store_id(), 'md_id' => get_md_id(),'mch_id' => get_mch_id()])->one(); if (get_md_id() > 0 && $md->is_single) { $food_payment = $md->food_payment; $food_paytype = $md->food_pay_type; } else if($mchModel){ $food_payment = $mchModel->food_payment; $food_paytype = $mchModel->food_pay_type; } else { $food_payment = $store->food_payment; $food_paytype = $store->food_pay_type; } if (!empty($food_payment)) { $food_pay_type = Json::decode($food_payment); $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'pay', Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store')['value']); $is_food_ok = false; if (!empty($pay_type_list_json)) { $pay_type_list = Json::decode($pay_type_list_json['value']); $user_pay_list_json = Option::get('payment_' . get_user_id(), get_store_id(), 'user')['value']; if ($user_pay_list_json) { $user_pay_list_arr = Json::decode($user_pay_list_json); foreach ($pay_type_list as $key => &$value) { if (isset($user_pay_list_arr[$key]) && $user_pay_list_arr[$key]['value'] == 0 && $value['value'] == 1) { $value['value'] = 0; } } } foreach ($pay_type_list as $index => $pay_type) { if ($index == 'friend' && $pay_type['value'] == 1) { $is_food_ok = true; break; } } } foreach ($food_pay_type as &$value) { if ($value['key'] == 'friend') { if ($is_food_ok && $value['value'] == 1) { $value['value'] = 1; } else { $value['value'] = 0; } } if ($value['key'] == 'friend') { $value['payment'] = 7; } if ($value['key'] == 'alipay') { $value['payment'] = 4; } if ($value['key'] == 'wechat') { $value['payment'] = 1; } if ($value['key'] == 'huodao') { $value['payment'] = 2; } if ($value['key'] == 'bytedance') { $value['payment'] = 5; } } $food_pay_list = $food_pay_type; } foreach ($food_pay_list as $k => $val) { if ($val['payment'] == 4 && is_wechat_platform() || ($val['payment'] == 4 && intval($val['value']) === 0)) { unset($food_pay_list[$k]); } if ($val['payment'] == 1 && is_alipay_platform() || ($val['payment'] == 1 && intval($val['value']) === 0)) { unset($food_pay_list[$k]); } if ($val['payment'] == 7 && intval($val['value']) === 0) { unset($food_pay_list[$k]); } if ($val['payment'] == 2 && intval($val['value']) === 0) { unset($food_pay_list[$k]); } if ($val['payment'] == 5 && intval($val['value']) === 0) { unset($food_pay_list[$k]); } } $food_pay_list = array_values($food_pay_list); // 点餐支付方式 $default_food_delivery = (int)Option::get('default_food_delivery', get_store_id(), 'store', 0)['value']; //到店自提 if($mchModel){ $default_food_delivery = (int)Option::get('default_food_delivery', get_mch_id(), 'mch', 0)['value']; } $food_pay_type = [ 'food_pay_type' => $food_paytype, 'food_payment' => $food_pay_list, 'default_food_delivery' => $default_food_delivery ]; // $food_pay_type = $food_pay_list; } if (get_md_id() > 0) { $province_name = District::findOne($md->province)->name; $city_name = District::findOne($md->city)->name; $district_name = District::findOne($md->district)->name; $md_info = [ 'is_md' => 1, 'name' => $md->name, 'detail_address' => $province_name . $city_name . $district_name . $md->address, 'distance' => Tools::getDistance($this->latitude, $this->longitude, $md->latitude, $md->longitude), 'longitude' => $md->longitude, 'latitude' => $md->latitude, 'logo' => $md->cover_url ]; } else { $province_name = District::findOne($store->province_id)->name; $city_name = District::findOne($store->city_id)->name; $district_name = District::findOne($store->district_id)->name; $lat = ''; $long = ''; $coordinate = explode(',', $store->coordinate); if ($coordinate) { $lat = $coordinate[0]; $long = $coordinate[1]; } $md_info = [ 'is_md' => 0, 'name' => $store->name, 'detail_address' => $province_name . $city_name . $district_name . $store->address, 'distance' => Tools::getDistance($this->latitude, $this->longitude, $lat, $long), 'longitude' => $long, 'latitude' => $lat, 'logo' => $store->logo ]; } if ($mchList[0]['goods_list'][0]['product_type'] == Goods::GOODS_TYPE_ADOPT) { $template_id = NoticeAction::getSendTamplateId(['order_pay', 'adopt_mature', 'adopt_order_confirm_mature']); } else { $noticeType = ['order_pay', 'order_submit']; if($this->send == 'shop'){ $noticeType[] = 'shop_arrive'; }else{ $noticeType[] = 'order_send'; } $template_id = NoticeAction::getSendTamplateId($noticeType, is_h5() ? 'wxaapi' : 'miapp'); } if ($this->is_worker) { goto is_worker; } //计算联盟券 $take_price = 0; $send_price = 0; // $send_profit_model = Option::findOne(['name' => 'store_send_profit']);//平台让利比例 // $this_store_send_profit_model= Option::findOne(['name' => 'store_this_profit','store_id' => get_store_id()]); // if($this_store_send_profit_model->value > 0){ // $basic_send_profit = $this_store_send_profit_model->value; // }else{ // $basic_send_profit = $send_profit_model->value; // } foreach ($mchList[0]['goods_list'] as $arr) { //TODO 新的 //计算返利 $send_price += $arr['send_price'] ?? 0; $take_price += $arr['take_price'] ?? 0; } $user = User::findOne(get_user_id()); $user_league_price = 0; $saas_user = SaasUser::findOne(['mobile' => $user->binding]); if($saas_user){ $user_league_price = $saas_user->league_price; } $show_saas_alliance_coupon = true; if (\Yii::$app->prod_is_dandianpu()) { $show_saas_alliance_coupon = false; } // // 随机立减 // $mchList[0]['rand_discount_price'] = 0; // // 此处做缓存,用于解决前端短时间内请求多次订单预览接口 // if ( // $mchList[0]['goods_list'][0]['product_type'] == Goods::GOODS_TYPE_NORMAL || // $mchList[0]['goods_list'][0]['product_type'] == Goods::GOODS_TYPE_VIRTUAL // ) { // $randDiscountCache = cache()->get('rand_discount_cache_' . get_user_id()); // if ($randDiscountCache) { // $randDiscountOption = $randDiscountCache; // } else { // $randDiscountOption = RandDiscount::getOption(\get_store_id(), $mchList[0]['total_price']); // cache()->set('rand_discount_cache_' . get_user_id(), $randDiscountOption, 3); // } // cache()->set('rand_discount_cache2_' . get_user_id(), $randDiscountOption); // if ($randDiscountOption['is_open'] && (float)$randDiscountOption['rand'] > 0) { // $mchList[0]['rand_discount_price'] = $randDiscountOption['rand']; // } // } is_worker: $invoiceConf = []; $invoice_is_open = \app\modules\admin\models\InvoiceForm::is_open($store->id, $invoiceConf); return [ 'code' => 0, 'msg' => 'OOKK', 'order_no' => $order_no, 'data' => [ 'user' => get_user(), 'user_integralPrice' => get_user()->integralPrice, 'invoice_is_open' => $invoice_is_open, 'invoiceConf' => $invoiceConf, 'goods_send_profit' => 0, 'store_send_profit' => 0, 'flag_id' => intval($flag_id), 'flag_type' => intval($flagType), 'table_info' => $tableInfo, 'take_price' => sprintf('%.2f',$take_price ?? 0), 'send_price' => sprintf('%.2f', $send_price ?? 0), 'user_league_price' => !$this->is_worker ? $user_league_price ?? 0 : 0, 'md_info' => !$this->is_worker ? $md_info : null, 'food_pay' => $food_pay_type, 'pay_type_list' => $food_pay_list ?: $this->getPayTypeList(), 'address' => $this->address, 'worker' => $this->worker, 'level' => !$this->is_worker ? $this->getLevelData() : null, 'mch_list' => $mchList, 'integral'=> $this->integral, 'goods_card_list' => !$this->is_worker ? $this->goodsCardList(): null, 'template_id' => $template_id, 'show_saas_alliance_coupon' => !$this->is_worker ? $show_saas_alliance_coupon : false, 'travel' => $this->is_worker ? $this->travel : null, 'agreement_id' => $agreement_id, 'agreement_title' => $agreement_title, ], ]; } }