| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models\order;
- use app\constants\OptionSetting;
- use app\models\District;
- use app\models\FoodFlag;
- use app\models\Goods;
- use app\models\Md;
- use app\models\Option;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\User;
- use app\utils\Delivery\Delivery;
- use app\utils\Notice\NoticeAction;
- use app\utils\OrderNo;
- use app\utils\Tools;
- use yii\helpers\Json;
- class OrderSubmitPreviewForm extends OrderForm
- {
- public function rules()
- {
- return parent::rules();
- }
- public function search()
- {
- if (!$this->validate())
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- // HKG 新增判断商城打烊状态 开始
- if(get_store_id() > 0 && Option::get(OptionSetting::MALL_STATUS,get_store_id(),'store',0)['value'] == 1)
- return [
- 'code' => 1,
- 'msg' => '商城已打烊~'
- ];
- // HKG 新增判断商城打烊状态 结束
- try {
- // 预生成订单号
- $order_no = OrderNo::getOrderNo(OrderNo::ORDER_ALLIANCE);
- cache()->set('delivery_order_no_' . get_saas_user_id(), $order_no);
- $storeList = $this->getStoreListData();
- if(isset($storeList['code']) && $storeList['code'] == 1){
- return $storeList;
- }
- } catch(\Exception $e) {
- return [
- 'code' => 1,
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'file' => $e->getFile(),
- ];
- }
- $food_pay_type = $store_info = [];
- $flag_id = 0;
- $store = Store::findOne(get_store_id());
- if (get_md_id() && (!empty(input_params('flag_id')) || !empty(input_params('table_num')))) {
- if (!empty(input_params('flag_id'))) {
- $flag_id = input_params('flag_id');
- } else {
- $flag_id = FoodFlag::findOne(['store_id' => get_store_id(), 'status' => 0, 'table_num' => input_params('table_num')])->id;
- }
- $food_payment = $store->food_payment;
- $food_paytype = $store->food_pay_type;
- $food_pay_list = [];
- if (!empty($food_payment)) {
- $food_pay_type = Json::decode($food_payment);
- // $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store');
- // $is_food_ok = false;
- // if (!empty($pay_type_list_json)) {
- // $pay_type_list = Json::decode($pay_type_list_json['value']);
- // 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['name']){
- $value['name'] = "朋友代付";
- }
- }
- if ($value['key'] == 'alipay') {
- $value['payment'] = 4;
- if(!$value['name']){
- $value['name'] = "支付宝支付";
- }
- }
- if ($value['key'] == 'wechat') {
- $value['payment'] = 1;
- if(!$value['name']){
- $value['name'] = "微信支付";
- }
- }
- if ($value['key'] == 'huodao') {
- $value['payment'] = 2;
- if(!$value['name']){
- $value['name'] = "货到付款";
- }
- }
- }
- $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]);
- }
- }
- $food_pay_list = array_values($food_pay_list);
- // 点餐支付方式
- $food_pay_type = [
- 'food_pay_type' => $food_paytype,
- 'food_payment' => $food_pay_list
- ];
- }
- $province_name = isset(District::findOne($store->province_id)->name) ? District::findOne($store->province_id)->name : '';
- $city_name = isset(District::findOne($store->city_id)->name) ? District::findOne($store->city_id)->name : '';
- $district_name = isset(District::findOne($store->district_id)->name) ? District::findOne($store->district_id)->name : '';
- list($lat, $long) = explode(',', empty($store->coordinate) ? ',' : $store->coordinate);
- $store_info = [
- '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
- ];
- //计算联盟券
- $take_price = 0;
- $send_price = 0;
- $user_league_price = \get_saas_user()->league_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 ($storeList[0]['goods_list'] as &$arr) {
- // $goods = Goods::findOne($arr['goods_id']);
- //TODO 新的
- //计算返利
- $send_price += $arr['send_price'] ?? 0;
- $take_price += $arr['take_price'] ?? 0;
- }
- $total_price = 0;
- foreach ($storeList as $store_item) {
- $total_price += $store_item['total_price'];
- }
- if (bcsub($total_price, $take_price, 2) <= 0) {
- $this->integral = 0;
- }
- return [
- 'code' => 0,
- 'msg' => 'OOKK',
- 'data' => [
- 'order_no' => $order_no,
- 'goods_send_profit' => 0,
- 'store_send_profit' => 0,
- 'flag_id' => intval($flag_id),
- 'store_info' => $store_info,
- 'food_pay' => $food_pay_type,
- 'pay_type_list' => $this->getPayTypeList(),
- 'address' => $this->address,
- 'take_price' => $take_price,
- 'send_price' => $send_price,
- 'user_league_price' => $user_league_price,
- //'level' => $this->getLevelData(),
- 'store_list' => $storeList,
- 'integral' => $this->integral,
- //'goods_card_list' => $this->goodsCardList(),
- 'template_id' => NoticeAction::getSendTamplateId(['order_pay', 'order_submit', 'order_send'])
- ],
- ];
- }
- }
|