CostOrderSubmitPreviewForm.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\adopt\models\client;
  8. use app\constants\OptionSetting;
  9. use app\models\Address;
  10. use app\models\Coupon;
  11. use app\models\CouponAutoSend;
  12. use app\models\FreeDeliveryRules;
  13. use app\models\Goods;
  14. use app\models\Level;
  15. use app\models\Mch;
  16. use app\models\OfferPrice;
  17. use app\models\Option;
  18. use app\models\Order;
  19. use app\models\OrderDetail;
  20. use app\models\PostageRules;
  21. use app\models\Shop;
  22. use app\models\TerritorialLimitation;
  23. use app\models\User;
  24. use app\models\UserCoupon;
  25. use app\plugins\adopt\models\AdoptOrderInfo;
  26. use app\plugins\adopt\models\AdoptSetting;
  27. use yii\base\Model;
  28. use yii\helpers\Json;
  29. class CostOrderSubmitPreviewForm extends Model
  30. {
  31. public $order_id;
  32. public $address_id;
  33. public $_from;
  34. public $longitude;
  35. public $latitude;
  36. public $store_id;
  37. public $store;
  38. public $user_id;
  39. public $order_type;
  40. public $weight;
  41. /** @var User $user */
  42. protected $user;
  43. public $address;
  44. protected $level;
  45. protected $integral;
  46. protected $keyword;
  47. public function rules()
  48. {
  49. $rules = [
  50. [['order_id', 'order_type'], 'required'],
  51. ['address_id', 'integer'],
  52. [['weight'], 'number'],
  53. [['longitude', 'latitude', '_from'], 'trim'],
  54. [['_from'], 'in', 'range' => ['app', 'mini']],
  55. ];
  56. return $rules;
  57. }
  58. public function afterValidate()
  59. {
  60. $this->user = User::findOne($this->user_id);
  61. $this->level = $this->getLevelData();
  62. $this->address = $this->getAddressData();
  63. $this->integral = [
  64. 'forehead' => 0,
  65. 'forehead_integral' => 0,
  66. 'integration' => Option::get(OptionSetting::STORE_INTEGRATION,get_store_id(), 'gift', Option::get(OptionSetting::STORE_INTEGRATION,get_store_id(), 'store')['value'])
  67. ];
  68. // parent::afterValidate();
  69. }
  70. public function search()
  71. {
  72. if (!$this->validate()){
  73. return [
  74. 'code' => 1,
  75. 'msg' => $this->getErrorSummary(false)[0],
  76. ];
  77. }
  78. $cost_detail = $this->getCostDetail();
  79. $AdoptSetting = AdoptSetting::findOne([ 'store_id' => $this->store_id,]);
  80. $free_preserve_time = $AdoptSetting->free_preserve_time;
  81. $preserve_day = $cost_detail['preserve_day'];
  82. $free_preserve_time_tips = '系统免费保管'.$free_preserve_time.'天,您当前已保管'.$preserve_day.'天';
  83. return [
  84. 'code' => 0,
  85. 'msg' => 'OOKK',
  86. 'data' => [
  87. 'pay_type_list' => $this->getPayTypeList(),
  88. 'address' => $this->address,
  89. 'cost_detail' => $cost_detail,
  90. 'free_preserve_time_tips' => $free_preserve_time_tips
  91. ],
  92. ];
  93. }
  94. public function getCostDetail() {
  95. $adopt_order = Order::find()->alias('o')
  96. ->where([
  97. 'o.store_id' => $this->store_id,
  98. // 'o.user_id' => $this->user_id,
  99. 'o.id' => $this->order_id,
  100. 'o.is_delete' => 0,
  101. ])
  102. ->leftJoin(AdoptOrderInfo::tableName() . ' aoi', "aoi.order_id = o.id ")
  103. ->leftJoin(OrderDetail::tableName() . ' od', "od.order_id = o.id ")
  104. ->leftJoin(Goods::tableName() . ' g', "od.goods_id = g.id ")
  105. ->andWhere([
  106. 'aoi.is_delete' => 0,
  107. ])
  108. ->select(['o.*', 'aoi.name as adopt_name', 'aoi.mobile as adopt_mobile', 'aoi.is_mature', 'aoi.mature_time',
  109. 'aoi.pick_method', 'aoi.pick_time', 'aoi.is_storage', 'aoi.storage_time', 'aoi.is_preserve', 'aoi.preserve_time',
  110. 'aoi.harvest_weight', 'aoi.billing_start_time', 'aoi.other_pick_fee', 'aoi.preserve_fee', 'aoi.harvest_weight',
  111. 'od.num', 'od.goods_id', 'g.freight', 'g.name', 'g.cover_pic', 'g.price' ])
  112. ->asArray()->one();
  113. $cost_list = [];
  114. if ($this->order_type == 0) {
  115. $cost_list = $adopt_order['other_pick_fee'] ? json_decode($adopt_order['other_pick_fee'], true) : [];
  116. }
  117. if ($this->order_type == 1) {
  118. $cost_list = $adopt_order['preserve_fee'] ? json_decode($adopt_order['preserve_fee'], true) : [];
  119. }
  120. $AdoptSetting = AdoptSetting::findOne(['store_id' => $this->store_id,]);
  121. $free_preserve_time = $AdoptSetting->free_preserve_time;
  122. $time = time();
  123. $total_pay_price = 0;
  124. if ($time > ($adopt_order['preserve_time'] + $free_preserve_time * 86400)) {
  125. $preserve_billing_day = ceil(($time - ($adopt_order['preserve_time'] + $free_preserve_time * 86400)) / 86400);
  126. } else {
  127. $preserve_billing_day = 0;
  128. }
  129. $preserve_day =$adopt_order['preserve_time'] ? ceil(($time - $adopt_order['preserve_time']) / 86400) : 0;
  130. $this->weight = $this->weight ? $this->weight : 0;
  131. $billing_weight = $this->weight * 2;
  132. foreach ($cost_list as $k => $v) {
  133. $pay_price = 0;
  134. if ($v['is_day'] == 1 && $v['is_weight'] == 1) {
  135. if ($v['is_free'] == 1) {
  136. $pay_price += $preserve_billing_day * $billing_weight * $v['price'];
  137. $cost_list[$k]['calculation_method'] = "1天*"."1斤*".$v['price']."元"."(".$preserve_billing_day."天".$billing_weight."斤".")";
  138. } else {
  139. $pay_price += $preserve_day * $billing_weight * $v['price'];
  140. $cost_list[$k]['calculation_method'] = "1天*"."1斤*".$v['price']."元"."(".$preserve_day."天".$billing_weight."斤".")";
  141. }
  142. } elseif ($v['is_day'] == 1 && $v['is_weight'] == 0){
  143. if ($v['is_free'] == 1) {
  144. $pay_price += $preserve_billing_day * $v['price'];
  145. $cost_list[$k]['calculation_method'] = "1天*".$v['price']."元"."(".$preserve_billing_day."天".")";
  146. } else {
  147. $pay_price += $preserve_day * $v['price'];
  148. $cost_list[$k]['calculation_method'] = "1天*".$v['price']."元"."(".$preserve_day."天".")";
  149. }
  150. } elseif ($v['is_day'] == 0 && $v['is_weight'] == 1){
  151. $pay_price += $billing_weight * $v['price'];
  152. $cost_list[$k]['calculation_method'] = "1斤*".$v['price']."元"."(".$billing_weight."斤".")";
  153. } else {
  154. $pay_price += $v['price'];
  155. $cost_list[$k]['calculation_method'] = '';
  156. }
  157. $pay_price = sprintf('%.2f', $pay_price);
  158. $cost_list[$k]['total_price'] = $pay_price;
  159. $total_pay_price += $pay_price;
  160. }
  161. $cost_detail['total_price'] = $total_pay_price;
  162. $cost_detail['cost_list'] = $cost_list;
  163. $cost_detail['harvest_weight'] = $adopt_order['harvest_weight'];
  164. $goods = [
  165. 'goods_id' => $adopt_order['goods_id'],
  166. 'num' => $adopt_order['num'],
  167. 'weight' => $this->weight * 1000,
  168. 'freight' => $adopt_order['freight'],
  169. 'name' => $adopt_order['name'],
  170. 'cover_pic' => $adopt_order['cover_pic'],
  171. 'price' => $adopt_order['price'],
  172. ];
  173. $goods_list[] = $goods;
  174. $mch['mch_id'] = 0;
  175. $mch['total_price'] = $cost_detail['pay_price'];
  176. if ($this->order_type == 1) {
  177. $express_price = $this->getExpressPrice($goods_list, $mch);
  178. } else {
  179. $express_price = 0;
  180. }
  181. $cost_detail['express_price'] = $express_price > 0? $express_price : 0;
  182. $cost_detail['pay_price'] = sprintf('%.2f', $total_pay_price + $cost_detail['express_price']);
  183. $cost_detail['goods'] = $goods;
  184. $cost_detail['preserve_day'] = $preserve_day;
  185. return $cost_detail;
  186. }
  187. protected function getAddress()
  188. {
  189. if (!$this->address) {
  190. if ($this->address_id) {
  191. $this->address = Address::findOne(['id' => $this->address_id, 'user_id' => get_saas_user_id(), 'is_delete' => 0]);
  192. } else {
  193. $this->address = Address::find()->where([
  194. 'user_id' => get_saas_user_id(),
  195. 'is_default' => 1,
  196. 'is_delete' => 0,
  197. ])->limit(1)->one();
  198. }
  199. }
  200. return (object)$this->address;
  201. }
  202. //获取收货地址,有address_id优先获取,没有则获取默认地址
  203. public function getAddressData()
  204. {
  205. $address = $this->getAddress();
  206. if (isset($address->id)) {
  207. return [
  208. 'id' => $address->id,
  209. 'name' => $address->name,
  210. 'mobile' => $address->mobile,
  211. 'province_id' => $address->province_id,
  212. 'province' => $address->province,
  213. 'city_id' => $address->city_id,
  214. 'city' => $address->city,
  215. 'district_id' => $address->district_id,
  216. 'district' => $address->district,
  217. 'detail' => $address->detail,
  218. 'is_default' => $address->is_default,
  219. 'latitude' => $address->latitude,
  220. 'longitude' => $address->longitude,
  221. ];
  222. } else {
  223. return null;
  224. }
  225. }
  226. //获取支付方式
  227. protected function getPayTypeList()
  228. {
  229. $adopt_setting = AdoptSetting::findOne(['store_id' => get_store_id()]);
  230. $adopt_payment = $adopt_setting->adopt_payment;
  231. $adopt_pay_list = [];
  232. if (!empty($adopt_payment)) {
  233. $adopt_pay_type = Json::decode($adopt_payment);
  234. // $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store');
  235. // $is_food_ok = false;
  236. // if (!empty($pay_type_list_json)) {
  237. // $pay_type_list = Json::decode($pay_type_list_json['value']);
  238. // foreach ($pay_type_list as $index => $pay_type) {
  239. // if ($index == 'friend' && $pay_type['value'] == 1) {
  240. // $is_food_ok = true;
  241. // break;
  242. // }
  243. // }
  244. // }
  245. foreach ($adopt_pay_type as &$value) {
  246. // if ($value['key'] == 'friend') {
  247. // if ($is_food_ok && $value['value'] == 1) {
  248. // $value['value'] = 1;
  249. // } else {
  250. // $value['value'] = 0;
  251. // }
  252. // }
  253. // if ($value['key'] == 'friend') {
  254. // $value['payment'] = 7;
  255. // }
  256. if ($value['key'] == 'alipay') {
  257. $value['payment'] = 4;
  258. }
  259. if ($value['key'] == 'wechat') {
  260. $value['payment'] = 1;
  261. }
  262. // if ($value['key'] == 'huodao') {
  263. // $value['payment'] = 2;
  264. // }
  265. }
  266. $adopt_pay_list = $adopt_pay_type;
  267. }
  268. foreach ($adopt_pay_list as $k => $val) {
  269. if ($val['payment'] == 4 && is_wechat_platform()) {
  270. unset($adopt_pay_list[$k]);
  271. }
  272. if ($val['payment'] == 1 && is_alipay_platform()) {
  273. unset($adopt_pay_list[$k]);
  274. }
  275. }
  276. $new_list = array_values($adopt_pay_list);
  277. return $new_list;
  278. }
  279. protected function getCouponList(&$mch)
  280. {
  281. if (!isset($mch['mch_id'])) {
  282. $mch['mch_id'] = 0;
  283. }
  284. $goods_total_price = isset($mch['total_price']) ? $mch['total_price'] : 0;
  285. $cat_ids = $this->getCatIdList($mch['goods_list'], $mch['mch_id']);
  286. $coupon_goods_id = $this->getGoodsIdList($mch['goods_list']);
  287. // Yii::error([$goods_total_price, $this->user_id, $this->store_id]);
  288. $list = UserCoupon::find()->alias('uc')
  289. ->leftJoin(['c' => Coupon::tableName()], 'uc.coupon_id=c.id')
  290. ->leftJoin(['cas' => CouponAutoSend::tableName()], 'uc.coupon_auto_send_id=cas.id')
  291. ->where([
  292. 'AND',
  293. ['uc.store_id' => $this->store_id],
  294. ['uc.is_delete' => 0],
  295. ['uc.is_use' => 0],
  296. ['uc.is_expire' => 0],
  297. ['uc.user_id' => $this->user_id],
  298. ['<=', 'c.min_price', $goods_total_price],
  299. ])
  300. ->select('uc.id user_coupon_id,c.mch_id,uc.is_use,uc.is_expire,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')
  301. ->asArray()->all();
  302. $events = [
  303. 0 => '平台发放',
  304. 1 => '分享红包',
  305. 2 => '购物返券',
  306. 3 => '领券中心',
  307. ];
  308. $max_price = isset($mch['total_price']) ? $mch['total_price'] : 0;
  309. $new_list = [];
  310. foreach ($list as $i => $item) {
  311. if ($item['begin_time'] > (strtotime(date('Y-M-d')) + 86400) || $item['end_time'] < time()) {
  312. continue;
  313. }
  314. $list[$i]['status'] = 0;
  315. if ($item['is_use']) {
  316. $list[$i]['status'] = 1;
  317. }
  318. if ($item['is_expire']) {
  319. $list[$i]['status'] = 2;
  320. }
  321. $list[$i]['min_price_desc'] = $item['min_price'] == 0 ? '无门槛' : '满' . $item['min_price'] . '元可用';
  322. $list[$i]['begin_time'] = date('Y.m.d H:i', (int)$item['begin_time']);
  323. $list[$i]['end_time'] = date('Y.m.d H:i', (int)$item['end_time']);
  324. if (!$item['event']) {
  325. if ($item['type'] == 2) {
  326. $list[$i]['event'] = $item['event'] = 3;
  327. } else {
  328. $list[$i]['event'] = $item['event'] = 0;
  329. }
  330. }
  331. if ($list[$i]['mch_id'] > 0) {
  332. $list[$i]['event_desc'] = Mch::findOne($list[$i]['mch_id'])->name;
  333. }else {
  334. $list[$i]['event_desc'] = $events[$item['event']];
  335. }
  336. $list[$i]['min_price'] = doubleval($item['min_price']);
  337. $list[$i]['sub_price'] = doubleval($item['sub_price']);
  338. if ($list[$i]['appoint_type'] == 1) {
  339. $list[$i]['cat_id_list'] = json_decode($list[$i]['cat_id_list']);
  340. if ($list[$i]['cat_id_list'] != null) {
  341. $goodsAdd = [];
  342. foreach ($mch['goods_list'] as $v2) {
  343. if (!in_array($v2['goods_id'], $goodsAdd)) {
  344. array_push($goodsAdd, $v2['goods_id']);
  345. }
  346. };
  347. if ($mch['price'] < $list[$i]['min_price']) {
  348. unset($list[$i]);
  349. continue;
  350. }
  351. }
  352. } elseif ($list[$i]['appoint_type'] == 2) {
  353. $list[$i]['goods_id_list'] = json_decode($list[$i]['goods_id_list']);
  354. if ($list[$i]['goods_id_list'] != null) {
  355. $current = array_intersect($list[$i]['goods_id_list'], $coupon_goods_id);
  356. if ($current) {
  357. } else {
  358. unset($list[$i]);
  359. continue;
  360. }
  361. }
  362. } else {
  363. if ($max_price < $list[$i]['min_price']) {
  364. unset($list[$i]);
  365. continue;
  366. }
  367. }
  368. $new_list[] = $list[$i];
  369. }
  370. $mch['coupon_list'] = $new_list;
  371. }
  372. protected function getLevelData()
  373. {
  374. $level = Level::find()->select([
  375. 'name', 'level', 'discount',
  376. ])->where(['level' => $this->user->level, 'store_id' => $this->store_id, 'is_delete' => 0])
  377. ->asArray()->one();
  378. return $level;
  379. }
  380. protected function getExpressPrice($goods_list,$mch)
  381. {
  382. $expressPrice = 0;
  383. if ($this->address) {
  384. $address = $this->address;
  385. // //先计算单品满件包邮和满额包邮
  386. // $resGoodsList = Goods::cutFull($mch['goods_list']);
  387. //再通过运费规则计算运费
  388. $expressPrice = PostageRules::getExpressPriceMore($this->store_id, $address['city_id'], $goods_list, $address['province_id']);
  389. }
  390. $expressPrice = $this->getFreeDeliveryRules($mch, $expressPrice);
  391. return $expressPrice >= 0 ? $expressPrice : 0;
  392. }
  393. /**
  394. * 计算打包费
  395. * @param $mch
  396. * @return int
  397. */
  398. protected function getDabaoPrice($mch)
  399. {
  400. $goods_list = $mch['goods_list'];
  401. $dabao_price = 0;
  402. foreach ($goods_list as $value) {
  403. $dabao_price += $value['dabao_price'];
  404. }
  405. return $dabao_price >= 0 ? $dabao_price : 0;
  406. }
  407. // 获取门店列表
  408. protected function getShopList()
  409. {
  410. $start = 0;
  411. $shop_table_name = Shop::tableName();
  412. $user_table_name = User::tableName();
  413. $address = Address::findOne($this->address['id']);
  414. $latitude = $address->latitude ? $address->latitude : 0;
  415. $longitude = $address->longitude ? $address->longitude : 0;
  416. $sql = "SELECT `s`.*, `u`.`nickname`, acos(cos({$latitude}*pi()/180 )*cos(s.latitude*pi()/180)*cos({$longitude}*pi()/180 -s.longitude*pi()/180)+sin({$latitude}*pi()/180 )*sin(s.latitude*pi()/180))*6370996.81 as
  417. distance FROM {$shop_table_name} `s` LEFT JOIN {$user_table_name} `u`
  418. ON s.id=u.shop_id WHERE ((`s`.`store_id`={$this->store_id}) AND (`s`.`is_delete`=0)) AND (`s`.`user_id` > 0) ";
  419. if ($this->keyword) {
  420. $sql .= " AND (`s`.`name` like '%{$this->keyword}%') ";
  421. }
  422. $sql .= "ORDER BY `distance` LIMIT {$start},30";
  423. $list = \Yii::$app->db->createCommand($sql)->queryAll();
  424. $shop = null;
  425. foreach ($list as $index => $item) {
  426. if ($item['is_default'] == 1) {
  427. $shop = $item;
  428. }
  429. $list[$index]['distance'] = round($item['distance']/1000, 2).'km';
  430. }
  431. return [
  432. 'list' => $list,
  433. 'shop' => $shop
  434. ];
  435. }
  436. // 获取起送规则
  437. protected function getOfferRule($mch)
  438. {
  439. $res = [
  440. 'is_allowed' => 0,
  441. 'total_price' => 0,
  442. 'msg' => ''
  443. ];
  444. if ($mch['mch_id'] > 0) {
  445. $res['msg'] = '商户不支持起送规则';
  446. return $res;
  447. }
  448. if ($mch['plugin_type'] == 2) {
  449. $res['msg'] = '砍价不支持起送规则';
  450. return $res;
  451. }
  452. if (!$this->address) {
  453. $res['msg'] = '请选择收货地址';
  454. return $res;
  455. }
  456. $offerRule = OfferPrice::findOne(['store_id' => get_store_id(),'is_delete' => 0]);
  457. if (!$offerRule) {
  458. $res['msg'] = '起送规则不存在';
  459. return $res;
  460. }
  461. if ($offerRule->is_enable == 0) {
  462. $res['msg'] = '起送规则未开启';
  463. return $res;
  464. }
  465. $ruleList = Json::decode($offerRule->detail);
  466. $res['total_price'] = $offerRule->price;
  467. if (is_array($ruleList)) {
  468. foreach ($ruleList as $value) {
  469. foreach ($value['province_list'] as $item) {
  470. if ($item['id'] == $this->address['city_id']) {
  471. $res['total_price'] = $value['offer_price'];
  472. }
  473. }
  474. }
  475. }
  476. if ($mch['total_price'] >= $res['total_price']) {
  477. $res['is_allowed'] = 0;
  478. } else {
  479. $res['is_allowed'] = 1;
  480. }
  481. $value = round($res['total_price'] - $mch['total_price'], 2);
  482. $res['msg'] = "自营商品,还差{$value}元起送";
  483. return $res;
  484. }
  485. protected function getTerritorialLimitation($mch)
  486. {
  487. $isArea = 0;
  488. if ($mch['mch_id'] > 0) {
  489. return $isArea;
  490. }
  491. if ($this->address) {
  492. $area = TerritorialLimitation::findOne([
  493. 'store_id' => $this->store_id,
  494. 'is_delete' => 0,
  495. 'is_enable' => 1,
  496. ]);
  497. if ($area) {
  498. $city_id = []; //限制的地区ID
  499. $detail = json_decode($area->detail);
  500. if (!is_array($detail)) {
  501. $detail = [];
  502. }
  503. foreach ($detail as $key => $value) {
  504. foreach ($value->province_list as $key2 => $value2) {
  505. $city_id[] = $value2->id;
  506. }
  507. }
  508. $addressArr = [
  509. $this->address['province_id'],
  510. $this->address['city_id'],
  511. $this->address['district_id']
  512. ];
  513. $addressArray = array_intersect($addressArr, $city_id);
  514. if (empty($addressArray)) {
  515. $isArea = 1;
  516. }
  517. }
  518. }
  519. return $isArea;
  520. }
  521. // 包邮规则
  522. protected function getFreeDeliveryRules($mch, $expressPrice)
  523. {
  524. if ($expressPrice == 0) {
  525. return $expressPrice;
  526. }
  527. if ($mch['mch_id'] == 0) {
  528. $free = FreeDeliveryRules::find()->where(['store_id' => $this->store_id, 'is_delete' => 0, 'mch_id' => 0])->asArray()->all();
  529. foreach ($free as $k => $v) {
  530. $city = json_decode($v['city'], true);
  531. foreach ($city as $v1) {
  532. if ($this->address['district_id'] == $v1['id'] && $mch['total_price'] >= $v['price']) {
  533. $expressPrice = 0;
  534. break;
  535. }
  536. }
  537. }
  538. } else {
  539. $free = FreeDeliveryRules::find()->where(['store_id' => $this->store_id, 'mch_id' => $mch['mch_id'], 'is_delete' => 0])->asArray()->all();
  540. foreach ($free as $k => $v) {
  541. $city = json_decode($v['city'], true);
  542. foreach ($city as $v1) {
  543. if ($this->address['district_id'] == $v1['id'] && $mch['total_price'] >= $v['price']) {
  544. $expressPrice = 0;
  545. break;
  546. }
  547. }
  548. }
  549. }
  550. return $expressPrice;
  551. }
  552. }