mch_list); if (!$data) { $this->addError($attr, "{$attr}数据格式错误。"); } $this->mch_list = $data; }], ]; return $rules; } // 走过验证后 查询相应数据 public function afterValidate() { $this->user = User::findOne($this->user_id); $this->level = $this->getLevelData(); $this->integral = [ 'forehead' => 0, 'forehead_integral' => 0, 'integration' => Option::get(OptionSetting::STORE_INTEGRATION, get_store_id(), 'gift', Option::get(OptionSetting::STORE_INTEGRATION, get_store_id(), 'store')['value'])['value'] ]; $this->saas_user = SaasUser::findOne(['mobile' => $this->user->binding]); parent::afterValidate(); } protected function getLevelData() { $level = Level::find()->select([ 'name', 'level', 'discount', ])->where(['level' => $this->user->level, 'store_id' => $this->store_id, 'is_delete' => 0]) ->asArray()->one(); return $level; } /** * @throws \Exception */ protected function getMchListData($submit = false) { foreach ($this->mch_list as $i => &$mch) { $mch['goods_list'] = $this->getGoodsList($mch['goods_list'], $submit); if (empty($mch['goods_list'])) { throw new \Exception($mch['goods_list']['msg'], 1); } if ($mch['goods_list']['code'] === 1) { throw new \Exception($mch['goods_list']['msg'], 1); } $is_integral = false; if( isset($mch['goods_list'][0]['product_type']) && $mch['goods_list'][0]['product_type'] == Goods::GOODS_TYPE_INTEGRAL){ $mch['name'] = '积分商品'; $is_integral = true; }else{ $mch['name'] = '平台自营'; } $send_type = Option::get(OptionSetting::STORE_SEND_TYPE, get_store_id(), 'store')['value']; $send_type = Option::get(OptionSetting::STORE_SEND_TYPE, get_store_id(), 'pay', $send_type); $send_type = $send_type ? Json::decode($send_type['value']) : []; $send_type_arr = []; if (isset($send_type['express']['value']) && $send_type['express']['value']) { $send_type_arr[] = 'express'; } if (isset($send_type['shop']['value']) && $send_type['shop']['value']) { $send_type_arr[] = 'shop'; } if ((isset($send_type['delivery']['value']) && $send_type['delivery']['value']) && $submit == false) { if(is_alipay_platform()){ $send_type_arr[] = 'delivery'; try{ $conf = ADelivery::getConf($this->store_id, get_mini_id(), 1); $check = $conf['check']; if($check['code'] == 0){ $send_type_arr[] = 'delivery'; } } catch (\Exception $e) { \Yii::error([__METHOD__, $this->store_id, get_mini_id(), $e]); } }else{ $res = Delivery::getBindAccount(); // 下单时判断是否可以同城配送 if (!empty($res['data']['shop_list'])) { $store = Store::findOne($this->store_id); if ($store->delivery_type > 0) { $shop_list = $res['data']['shop_list']; $delivery_arr = array_column($shop_list, 'delivery_id'); $delivery_arr[] = 'TEST'; $delivery_arr_id = array_column($shop_list, null, 'delivery_id'); if (in_array(Delivery::$deliveryIdArr[$store->delivery_type], $delivery_arr) && $delivery_arr_id[Delivery::$deliveryIdArr[$store->delivery_type]]['audit_result'] == 0) { $send_type_arr[] = 'delivery'; } } } } } $mch['send_type'] = $send_type_arr; $mch['shop_list'] = []; !isset($mch['is_shop']) && $mch['is_shop'] = ''; $total_price = 0; $level_price = 0; $integral = [ 'forehead' => 0, 'forehead_integral' => 0 ]; $mch['plugin_type'] = isset($mch['plugin_type']) ? $mch['plugin_type'] : 0; foreach ($mch['goods_list'] as &$_goods) { if (in_array($_goods['product_type'], [1, 2])) { $mch['send_type'] = ['shop']; } if (in_array($_goods['product_type'], [1, 2]) && $submit == true) { $res = $this->bookCheckGoodsNum($_goods, $_goods['product_type']); if ($res['code'] != 0) { throw new \Exception($res['msg'], 1); } } $_goods['form'] = []; $total_price += doubleval($_goods['price']); if ((int)$_goods['product_type'] === 2) { $_goods['level_price'] = sprintf('%.2f', $mch['list']['price']); $_goods['price'] = $mch['list']['price']; } $level_price += doubleval($_goods['level_price']) > 0 ? doubleval($_goods['level_price']) : doubleval($_goods['price']); $_goods['integral'] = [ 'forehead' => doubleval($_goods['resIntegral']['forehead']), 'forehead_integral' => doubleval($_goods['resIntegral']['forehead_integral']) ]; $integral['forehead'] += doubleval($_goods['resIntegral']['forehead']); $integral['forehead_integral'] += doubleval($_goods['resIntegral']['forehead_integral']); unset($_goods['is_form']); unset($_goods['form_name']); } $integral['forehead'] = round($integral['forehead'], 2); $mch['total_price'] = !empty($this->verify_card_id) ? 0.00 : sprintf('%.2f', $total_price); $mch['level_price'] = !empty($this->verify_card_id) ? 0.00 : sprintf('%.2f', $level_price); $mch['integral'] = !empty($this->verify_card_id) ? [] : $integral; if($is_integral){ //积分兑换商品不能使用优惠券 或 秒杀活动中不允许使用优惠券则所有商品不允许使用优惠券 $mch['coupon_list'] = []; }else{ $this->getCouponList($mch); } $mch['express_price'] = 0; $mch['offer_rule'] = $this->getOfferRule($mch); if(empty(input_params('flag_id'))){ $mch['is_area'] = 0; } // 如果是点餐的商品,结构需要变一下 /*if (get_md_id() && (!empty(input_params('flag_id')) || !empty(input_params('table_num'))) && !$submit) { $user_list = []; $user_ids = array_unique(array_column($mch['goods_list'], 'user_id')); foreach ($user_ids as $user_id) { $goods_list = []; foreach ($mch['goods_list'] as $item) { if ($item['user_id'] == $user_id) { $goods_list[] = $item; } } $saas_user = SaasUser::findOne(['mobile' => User::findOne($user_id)->binding]); $user_list[] = [ 'name' => $saas_user->name, 'avatar' => $saas_user->avatar, 'user_id' => $user_id, 'goods_list' => $goods_list ]; } $mch['goods_list'] = $user_list; }*/ } return $this->mch_list; } protected function getGoodsList($goods_list, $submit) { // 获取卡券绑定的运费模板id $goodsIds = []; foreach ($goods_list as $i => &$item) { if(!isset($item['goods_id'])){ unset($goods_list[$i]); continue; } $attr_id_list = []; foreach ($item['attr'] as $_a) { array_push($attr_id_list, $_a['attr_id']); } $goods = Goods::findOne([ 'store_id' => get_store_id(), 'id' => $item['goods_id'], ]); if (!$goods) { unset($goods_list[$i]); continue; } if (($goods->confine_count && $goods->confine_count > 0)) { $goodsNum = Goods::getBuyNum($this->user, $goods->id); if ($goodsNum) { } else { $goodsNum = 0; } $goodsTotalNum = intval($goodsNum + $item['num']); if ($goodsTotalNum > $goods->confine_count) { throw new \Exception('商品:' . $goods->name . ' 只允许购买' . $goods->confine_count . $goods->unit, 1); } } $attr_info = $goods->getAttrInfo($attr_id_list); //判断是否为云仓商品 // if (!empty($goods->cloud_goods_id) && !$goods->is_wholesale) { // $goods_url = "/goods/getAttrParams"; // $param = [ // 'id' => $goods->cloud_goods_id // ]; // //请求接口 // $domain = (new OptionSetting)->getCloudDomainName(); // $goodsInfo = cloud_post($domain.$goods_url,$param); // $goodsInfo = json_decode($goodsInfo, true); // $goodsInfo = $goodsInfo['data']; // // //如果没有上架或审核未通过则不允许购买 // if ((int)$goodsInfo['status'] === 0 || (int)$goodsInfo['is_audit'] !== 2) { // //商品下架 // Goods::updateAll(['status' => 0, 'store_id' => get_store_id()],['cloud_goods_id' => $goods->cloud_goods_id]); // unset($goods_list[$i]); // continue; // } // // //如果使用规格 // if (!empty($goodsInfo['use_attr']) && (int)$goodsInfo['use_attr'] === 1) { // $goods_2 = new Goods(); // $goods_2->attr = $goods->attr; // $res_attr = $goods_2->getAttrGroupList(); // // if ($res_attr) { // foreach ($res_attr as &$attr_item) { // unset($attr_item->attr_group_id); // foreach ($attr_item->attr_list as &$list_item) { // unset($list_item->attr_id); // } // } // } // //判断规格名称是否一致 // $res_attr = json_decode(json_encode($res_attr), true); // if ($res_attr != $goodsInfo['AttrGroupList']) { // //商品下架 // Goods::updateAll(['status' => 0, 'store_id' => get_store_id()],['cloud_goods_id' => $goods->cloud_goods_id]); // unset($goods_list[$i]); // continue; // } // $attrs = json_decode($goodsInfo['attrs'], true); // foreach ($attrs as $attr_item) { // //如果供货商的商品规格包含购买的 // if (in_array($attr_item['attr_id'], $attr_id_list)) { // //判断库存无 或者 供货商库存小于购买的商品数量 // if ((int)$attr_item['num'] <= 0) { // //商品下架 // Goods::updateAll(['status' => 0, 'store_id' => get_store_id()],['cloud_goods_id' => $goods->cloud_goods_id]); // unset($goods_list[$i]); // continue; // } // } // } // } else { // //如果不使用规格 // if ((int)$goodsInfo['num'] <= 0 || $goodsInfo['name'] != $goods->name) { // Goods::updateAll(['status' => 0, 'store_id' => get_store_id()],['cloud_goods_id' => $goods->cloud_goods_id]); // unset($goods_list[$i]); // continue; // } // } // } $attr_list = Attr::find()->alias('a') ->select('ag.id AS attr_group_id,ag.attr_group_name,a.id AS attr_id,a.attr_name') ->leftJoin(['ag' => AttrGroup::tableName()], 'a.attr_group_id=ag.id') ->where(['a.id' => $attr_id_list, 'ag.store_id' => get_store_id(),]) ->asArray()->all(); $item['user_id'] = !empty($this->user) ? $this->user->id : 0; $item['attr_list'] = $attr_list; $item['goods_id'] = $goods->id; $item['mch_id'] = $goods->mch_id; $item['rate'] = $goods->rate; $item['rate_type'] = $goods->rate_type; $item['goods_name'] = $goods->name; $item['goods_pic'] = $attr_info['pic'] ? $attr_info['pic'] : $goods->cover_pic; //如果没有使用规格,则使用商品售价 否则使用规格售价 $item['price'] = sprintf('%.2f', (($goods->use_attr ? $attr_info['price'] : $goods->price) * $item['num'])); if ($item['new_price'] > 0) { $goods->price = $attr_info['price'] = $item['price'] = $item['new_price']; } $item['single_price'] = !empty($this->verify_card_id) ? 0 : sprintf('%.2f', $attr_info['price']); $item['weight'] = $goods->weight; if (!empty($this->verify_card_id)) { $item['integral'] = 0; } else { $item['integral'] = $goods->integral ? $goods->integral : 0; } $item['integral_price'] = $goods->integral_price; $item['freight'] = !empty($VerifyCard['freight_id']) ? $VerifyCard['freight_id'] : $goods->freight; $item['full_cut'] = $goods->full_cut; $item['goods_cat_id'] = $goods->cat_id; $item['id'] = $goods->id; $item['verify_card_id'] = []; $item['type'] = $goods->type; $item['delivery_type'] = Json::decode($goods->delivery_type); /* if (get_md_id() && empty(input_params('flag_id'))) { $md_goods = MdGoods::findOne(['goods_id' => $goods->id, 'md_id' => get_md_id()]); if ($md_goods) { $item['delivery_type'] = Json::decode($md_goods->delivery_type); } }*/ // 当前选择的规格 $attrIdArr = []; foreach ($item['attr_list'] as $attrListItem) { $attrIdArr[] = $attrListItem['attr_id']; } $GoodsFullMinus = GoodsFullMinus::find() ->select('*') ->where(['store_id' => get_store_id(), 'goods_id' => $goods->id, 'is_delete' => 0]) ->orderBy('full_minus_num ASC')->asArray()->all(); // 门店逻辑 $attr = $goods->attr; $price = $goods->price; // 门店逻辑 if (!empty($this->md_id)) { $md_goods = MdGoods::findOne(['goods_id' => $goods->id, 'md_id' => $this->md_id]); if ($md_goods) { $attr = $md_goods->attr; $price = $md_goods->price; } } if ($item['new_price'] > 0) { $mch_attr_id = array_column($item['attr'], 'attr_id'); sort($mch_attr_id); $attr_ = json_decode($attr, true); foreach ($attr_ as &$goods_attr_item) { $goods_attr_id = array_column($goods_attr_item['attr_list'], 'attr_id'); sort($goods_attr_id); if (!array_diff($goods_attr_id, $mch_attr_id)) { $goods_attr_item['price'] = $item['new_price']; } } $attr = json_encode($attr_, JSON_UNESCAPED_UNICODE); $price = $item['new_price']; $goods->is_level = 0; } /*if (get_md_id() && empty(input_params('flag_id'))) { $md_goods = MdGoods::findOne(['goods_id' => $goods->id, 'md_id' => get_md_id()]); if ($md_goods) { $attr = $md_goods->attr; $price = $md_goods->price; } }*/ $otherData = []; $this->user && $otherData = ['user'=> $this->user]; $other['form'] = 'cashier'; $res = \app\modules\client\models\v1\common\CommonGoods::currentGoodsAttr([ 'attr' => $attr, 'price' => $price, 'is_level' => $goods->is_level, 'mch_id' => $goods->mch_id, 'full_minus' => $GoodsFullMinus, 'unit' => $goods->unit, 'use_attr' => $goods->use_attr, 'md_id' => $this->md_id, ], $attrIdArr, $otherData, $item['num']); $item['batch_price_tips'] = $res['batch_price_tips']; $item['current_batch_price_tips'] = $res['current_batch_price_tips']; $item['price'] = sprintf('%.2f', ($res['price'] * $item['num'])); $item['level_price'] = sprintf('%.2f', ($res['level_price'] * $item['num'])); $item['is_level'] = $res['is_level']; $send_integral_profit = Option::get(OptionSetting::SEND_INTEGRAL_PROFIT, get_store_id(), 'gift', Option::get(OptionSetting::SEND_INTEGRAL_PROFIT, get_store_id(), 'store')['value'])['value']; $integralArr = $this->getIntegral((object)$item, Option::get(OptionSetting::STORE_INTEGRAL,get_store_id(), 'gift', Option::get(OptionSetting::STORE_INTEGRAL,get_store_id(), 'store')['value'])['value'], $goodsIds, $send_integral_profit); $item['give'] = $integralArr['give']; $item['resIntegral'] = $integralArr['resIntegral']; $goodsIds[] = $goods->id; $item['goods_card_list'] = Goods::getGoodsCard($goods->id); $item['is_form'] = $goods->is_form; $item['form_name'] = $goods->form_name; $item['product_type'] = $goods->product_type; /*$res = $this->getSceKillGoodsPrice($goods, $attr_id_list, $submit, $item['num']); if ($res['code'] === 0) { $item['is_level'] = 0; if ($res['data'] > 0) { $item['price'] = $item['level_price'] = sprintf('%.2f', ($res['data'] * $item['num'])); } } else { return $res; }*/ if ($goods->product_type == Goods::GOODS_TYPE_ADOPT) { $adopt_goods = AdoptGoods::find()->where(['goods_id' => $goods->id,'is_delete' => 0])->one(); $item['desc'] = $adopt_goods->desc; } } // 和空数组合并重建索引,避免出现因索引key间断导致客户端显示问题 return array_merge($goods_list, []); } //积分计算 /** * @param $goods_item object 重新编写的goods_item * @param $store_integral int 商城设置的积分规则 * @param $goods_id array 已设置积分的商品id数组 * @return array */ protected function getIntegral($goods_item, $store_integral, $goods_id = array(), $send_integral_profit = 0) { $integral = json_decode($goods_item->integral, true); $resIntegral = [ 'forehead' => 0, 'forehead_integral' => 0, ]; if ($integral) { // 赠送积分计算 $give = $integral['give']; if (strpos($give, '%') !== false) { // 百分比 $give = trim($give, '%'); $goods_item->give = (int)($goods_item->price * ($give / 100)); } else { // 固定积分 $goods_item->give = (int)($give * $goods_item->num); } if ($give <= 0 && $send_integral_profit > 0) { $goods_item->give = (int)(intval($goods_item->price) * ($send_integral_profit / 100)); } // 抵扣积分计算 $forehead = $integral['forehead']; if ($forehead) { if (strpos($forehead, '%') !== false) {//百分比积分抵扣计算 if ($forehead >= 100) { $forehead = 100; } if ($integral['more'] == '1') {//多件累计计算 $resIntegral['forehead_integral'] = (int)(($forehead / 100) * $goods_item->price * $store_integral); } else { if (!in_array($goods_item->id, $goods_id)) { //不允许多件累计 同id商品值计算一次积分抵扣 $resIntegral['forehead_integral'] = (int)(($forehead / 100) * $goods_item->single_price * $store_integral); } } } else { // if ($integral['more'] == '1') { // $resIntegral['forehead_integral'] = (int)($store_integral * $goods_item->price); // if ($goods_item->price > ($forehead * $goods_item->num)) { // $resIntegral['forehead_integral'] = (int)($forehead * $goods_item->num * $store_integral); // } // } else { // if (!in_array($goods_item->id, $goods_id)) { // $goodsPrice = $goods_item->single_price; // $resIntegral['forehead_integral'] = (int)($store_integral * $goodsPrice); // if ($goodsPrice > $forehead) { // if ($forehead > 0) { // $resIntegral['forehead_integral'] = (int)($forehead * $store_integral); // } else { // $resIntegral['forehead_integral'] = 0; // } // } // } // } // 累计 $resIntegral['forehead_integral'] = (int)($store_integral * $goods_item->price); if ($goods_item->price > ($forehead * $goods_item->num)) { $resIntegral['forehead_integral'] = (int)($forehead * $goods_item->num * $store_integral); } } } if ($this->integral['forehead_integral'] < $this->user->integral) { $resetIntegral = $this->user->integral - $this->integral['forehead_integral']; $resIntegral['forehead_integral'] = $resIntegral['forehead_integral'] >= $resetIntegral ? $resetIntegral : $resIntegral['forehead_integral']; $resIntegral['forehead'] = $store_integral ? sprintf("%.2f", ($resIntegral['forehead_integral'] / $store_integral)) : 0; $this->integral['forehead_integral'] += $resIntegral['forehead_integral']; $this->integral['forehead'] += $resIntegral['forehead']; } else { $resIntegral['forehead_integral'] = 0; $resIntegral['forehead'] = 0; } } return [ 'resIntegral' => $resIntegral, 'give' => $goods_item->give ?? '' ]; } protected function getCouponList(&$mch) { // if (get_md_id()) { // $mch['coupon_list'] = []; // return; // } if (!isset($mch['mch_id'])) { $mch['mch_id'] = 0; } $goods_total_price = $mch['total_price']; $cat_ids = $this->getCatIdList($mch['goods_list'],$mch['mch_id']); $coupon_goods_id = $this->getGoodsIdList($mch['goods_list']); $list = UserCoupon::find()->alias('uc') ->leftJoin(['c' => Coupon::tableName()], 'uc.coupon_id=c.id') ->leftJoin(['cas' => CouponAutoSend::tableName()], 'uc.coupon_auto_send_id=cas.id') ->where([ 'AND', ['uc.is_delete' => 0], ['uc.is_use' => 0], ['c.mch_id' => $mch['mch_id']], ['uc.is_expire' => 0], ['uc.user_id' => $this->user_id], ['<=', 'c.min_price', $goods_total_price], ]) ->andWhere($mch['plugin_type'] == 6 ? ['c.appoint_type' => 3] : [ 'OR', ['<>', 'c.appoint_type', 3], 'c.appoint_type IS NULL' ]) ->select('c.name, c.expire_day, c.id, c.expire_type, c.discount_type, c.discount, c.discount_max_price, uc.id user_coupon_id,c.mch_id,c.rule,c.sub_price,c.min_price,cas.event,uc.begin_time,uc.end_time,uc.type,c.appoint_type,c.cat_id_list,c.goods_id_list') ->asArray()->all(); $events = [ 0 => '平台发放', 1 => '分享红包', 2 => '购物返券', 3 => '领券中心', ]; $max_price = 0; if ($mch['plugin_type'] == 6) { $max_price = $mch['total_price']; } else { foreach ($mch['goods_list'] as $v) { $max_price += $v['price']; } } $new_list = []; foreach ($list as $i => $item) { if ($item['expire_type'] == 1) { if ($item['end_time'] > 0) { if (time() > $item['end_time']) { continue; } } } if ($item['expire_type'] == 2) { if (time() > $item['end_time'] || time() < $item['begin_time']) { continue; } } $list[$i]['status'] = 0; if (isset($item['is_use']) && $item['is_use']) { $list[$i]['status'] = 1; } if (isset($item['is_expire']) && $item['is_expire']) { $list[$i]['status'] = 2; } $list[$i]['min_price_desc'] = $item['min_price'] == 0 ? '无门槛' : '满' . $item['min_price'] . '元可用'; $list[$i]['begin_time'] = date('Y.m.d H:i', (int)$item['begin_time']); $list[$i]['end_time'] = date('Y.m.d H:i', (int)$item['end_time']); $list[$i]['discount_type'] = $item['discount_type']; $list[$i]['discount'] = $item['discount']; if (!$item['event']) { if ($item['type'] == 2) { $list[$i]['event'] = $item['event'] = 3; } else { $list[$i]['event'] = $item['event'] = 0; } } $list[$i]['event_desc'] = $events[$item['event']] ?: '领券中心'; $list[$i]['min_price'] = doubleval($item['min_price']); if ($list[$i]['discount_type'] == 1) { $list[$i]['sub_price'] = round($mch['total_price'] - doubleval($mch['total_price'] * $list[$i]['discount'] / 10), 2); if($item['discount_max_price'] > 0 && $list[$i]['sub_price'] > $item['discount_max_price']){ $list[$i]['sub_price'] = $item['discount_max_price']; } } else { $list[$i]['sub_price'] = doubleval($item['sub_price']); } if ($list[$i]['appoint_type'] == 1) { $list[$i]['cat_id_list'] = json_decode($list[$i]['cat_id_list']); if ($list[$i]['cat_id_list'] != null) { $current = array_intersect($list[$i]['cat_id_list'], $cat_ids); if ($current) { $goodsAdd = []; $price = 0; foreach ($current as $v) { foreach ($mch['goods_list'] as $v2) { if (in_array($v, $v2['cat_id']) && !in_array($v2['goods_id'], $goodsAdd)) { $price += $v2['price']; array_push($goodsAdd, $v2['goods_id']); } }; } if ($price < $list[$i]['min_price']) { unset($list[$i]); continue; } } else { unset($list[$i]); continue; } } } elseif ($list[$i]['appoint_type'] == 2) { $list[$i]['goods_id_list'] = json_decode($list[$i]['goods_id_list']); if ($list[$i]['goods_id_list'] != null) { $current = array_intersect($list[$i]['goods_id_list'], $coupon_goods_id); if ($current) { $goodsAdd = []; $price = 0; foreach ($current as $v) { foreach ($mch['goods_list'] as $v2) { if ($v == $v2['goods_id'] && !in_array($v2['goods_id'], $goodsAdd)) { $price += $v2['price']; } } } if ($price < $list[$i]['min_price']) { unset($list[$i]); continue; } } else { unset($list[$i]); continue; } } } else { if ($max_price < $list[$i]['min_price']) { unset($list[$i]); continue; } } $new_list[] = $list[$i]; } if (!empty($this->verify_card_id)) { $mch['coupon_list'] = []; } else { $mch['coupon_list'] = $new_list; } } protected function getCatIdList(&$goods_list,$mch_id = 0) { $cat_id_list = []; foreach ($goods_list as &$goods) { if ($goods['goods_cat_id'] == 0) { if ($mch_id > 0) { $goods_cat_list = MchGoodsCat::find() ->select('cat_id')->where([ 'goods_id' => $goods['goods_id'], ])->all(); }else { $goods_cat_list = GoodsCat::find() ->select('cat_id')->where([ 'goods_id' => $goods['goods_id'], 'is_delete' => 0, ])->all(); } foreach ($goods_cat_list as $goods_cat) { $cat_id_list[] = $goods_cat->cat_id; $goods['cat_id'][] = $goods_cat->cat_id; } } else { $cat_id_list[] = $goods['goods_cat_id']; $goods['cat_id'][] = $goods['goods_cat_id']; } $cat_parent_list = Cat::find()->select('parent_id') ->andWhere(['id' => $goods['cat_id'], 'store_id' => $this->store_id, 'is_delete' => 0])->andWhere(['>', 'parent_id', 0]) ->column(); $cat_id_list = array_merge($cat_parent_list, $cat_id_list); $goods['cat_id'] = array_merge($cat_parent_list, is_array($goods['cat_id']) ? $goods['cat_id'] : []); } unset($goods); return array_unique($cat_id_list); } protected function getGoodsIdList($goods_list) { $goods_id_list = []; foreach ($goods_list as $goods) { $goods_id_list[] = $goods['goods_id']; } return $goods_id_list; } // 获取起送规则 protected function getOfferRule($mch) { $res = [ 'is_allowed' => 0, 'total_price' => 0, 'msg' => '' ]; return $res; } protected function getAddress() { $saas_user = $this->saas_user; $this->address = Address::find()->where([ 'user_id' => $saas_user->id, 'is_delete' => 0, ])->asArray()->all(); return $this->address; } }