OrderSubmitPreviewForm.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * @Author: kai
  9. * @Date: 2021-03-02 09:50:20
  10. * @LastEditTime: 2021-04-23 13:39:19
  11. * @LastEditors: Please set LastEditors
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\modules\client\models\v1\order\OrderSubmitPreviewForm.php
  14. */
  15. namespace app\modules\client\models\v1\pt\order;
  16. use app\constants\OptionSetting;
  17. use app\models\District;
  18. use app\models\FoodFlag;
  19. use app\models\Goods;
  20. use app\models\Md;
  21. use app\models\Option;
  22. use app\models\Store;
  23. use app\utils\Notice\NoticeAction;
  24. use app\utils\OrderNo;
  25. use app\utils\Tools;
  26. use yii\helpers\Json;
  27. class OrderSubmitPreviewForm extends OrderForm
  28. {
  29. public function rules()
  30. {
  31. return parent::rules();
  32. }
  33. public function search()
  34. {
  35. if (!$this->validate())
  36. return [
  37. 'code' => 1,
  38. 'msg' => $this->getErrorSummary(false)[0],
  39. ];
  40. // HKG 新增判断商城打烊状态 开始
  41. if(Option::get(OptionSetting::MALL_STATUS,get_store_id(),'store',0)['value'] == 1)
  42. return [
  43. 'code' => 1,
  44. 'msg' => '商城已打烊~'
  45. ];
  46. // HKG 新增判断商城打烊状态 结束
  47. try {
  48. // 预生成订单号
  49. $order_no = OrderNo::getOrderNo(OrderNo::ORDER_PT);
  50. cache()->set('delivery_order_no_' . get_user_id(), $order_no);
  51. $mchList = $this->getMchListData();
  52. if(isset($mchList['code']) && $mchList['code'] == 1){
  53. return $mchList;
  54. }
  55. } catch(\Exception $e) {
  56. return [
  57. 'code' => 1,
  58. 'line' => $e->getLine(),
  59. 'msg' => $e->getMessage(),
  60. 'file' => $e->getFile(),
  61. ];
  62. }
  63. $food_pay_type = [];
  64. $md_info = [];
  65. $flag_id = 0;
  66. $store = Store::findOne(get_store_id());
  67. // if (get_md_id() && (!empty(input_params('flag_id')) || !empty(input_params('table_num')))) {
  68. // if (!empty(input_params('flag_id'))) {
  69. // $flag_id = input_params('flag_id');
  70. // } else {
  71. // $flag_id = FoodFlag::findOne(['store_id' => get_store_id(), 'md_id' => get_md_id(), 'status' => 0, 'table_num' => input_params('table_num')])->id;
  72. // }
  73. // if (get_md_id() > 0) {
  74. // $food_payment = $md->food_payment;
  75. // $food_paytype = $md->food_pay_type;
  76. // } else {
  77. // $food_payment = $store->food_payment;
  78. // $food_paytype = $store->food_pay_type;
  79. // }
  80. // $food_pay_list = [];
  81. // if (!empty($food_payment)) {
  82. // $food_pay_type = Json::decode($food_payment);
  83. // $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store');
  84. // $is_food_ok = false;
  85. // if (!empty($pay_type_list_json)) {
  86. // $pay_type_list = Json::decode($pay_type_list_json['value']);
  87. // foreach ($pay_type_list as $index => $pay_type) {
  88. // if ($index == 'friend' && $pay_type['value'] == 1) {
  89. // $is_food_ok = true;
  90. // break;
  91. // }
  92. // }
  93. // }
  94. // foreach ($food_pay_type as &$value) {
  95. // if ($value['key'] == 'friend') {
  96. // if ($is_food_ok && $value['value'] == 1) {
  97. // $value['value'] = 1;
  98. // } else {
  99. // $value['value'] = 0;
  100. // }
  101. // }
  102. // if ($value['key'] == 'friend') {
  103. // $value['payment'] = 7;
  104. // }
  105. // if ($value['key'] == 'alipay') {
  106. // $value['payment'] = 4;
  107. // }
  108. // if ($value['key'] == 'wechat') {
  109. // $value['payment'] = 1;
  110. // }
  111. // if ($value['key'] == 'huodao') {
  112. // $value['payment'] = 2;
  113. // }
  114. // if ($value['key'] == 'bytedance') {
  115. // $value['payment'] = 5;
  116. // }
  117. // }
  118. // $food_pay_list = $food_pay_type;
  119. //
  120. // }
  121. // foreach ($food_pay_list as $k => $val) {
  122. // if ($val['payment'] == 4 && is_wechat_platform()) {
  123. // unset($food_pay_list[$k]);
  124. // }
  125. // if ($val['payment'] == 1 && is_alipay_platform()) {
  126. // unset($food_pay_list[$k]);
  127. // }
  128. // }
  129. // $food_pay_list = array_values($food_pay_list);
  130. // // 点餐支付方式
  131. // $food_pay_type = [
  132. // 'food_pay_type' => $food_paytype,
  133. // 'food_payment' => $food_pay_list
  134. // ];
  135. // }
  136. if (get_md_id() > 0) {
  137. $md = Md::findOne(get_md_id());
  138. $province_name = District::findOne($md->province)->name;
  139. $city_name = District::findOne($md->city)->name;
  140. $district_name = District::findOne($md->district)->name;
  141. $md_info = [
  142. 'is_md' => 1,
  143. 'name' => $md->name,
  144. 'detail_address' => $province_name . $city_name . $district_name . $md->address,
  145. 'distance' => Tools::getDistance($this->latitude, $this->longitude, $md->latitude, $md->longitude),
  146. 'longitude' => $md->longitude,
  147. 'latitude' => $md->latitude,
  148. 'logo' => $md->cover_url
  149. ];
  150. } else {
  151. $province_name = District::findOne($store->province_id)->name;
  152. $city_name = District::findOne($store->city_id)->name;
  153. $district_name = District::findOne($store->district_id)->name;
  154. $lat = '';
  155. $long = '';
  156. $coordinate = explode(',', $store->coordinate);
  157. if ($coordinate) {
  158. $lat = $coordinate[0];
  159. $long = $coordinate[1];
  160. }
  161. $md_info = [
  162. 'is_md' => 0,
  163. 'name' => $store->name,
  164. 'detail_address' => $province_name . $city_name . $district_name . $store->address,
  165. 'distance' => Tools::getDistance($this->latitude, $this->longitude, $lat, $long),
  166. 'longitude' => $long,
  167. 'latitude' => $lat,
  168. 'logo' => $store->logo
  169. ];
  170. }
  171. $template_id = NoticeAction::getSendTamplateId(['order_pay', 'order_submit', 'order_send']);
  172. return [
  173. 'code' => 0,
  174. 'msg' => 'OOKK',
  175. 'data' => [
  176. 'flag_id' => intval($flag_id),
  177. 'md_info' => $md_info,
  178. 'food_pay' => $food_pay_type,
  179. 'pay_type_list' => $this->getPayTypeList(),
  180. 'take_price' => sprintf('%.2f',0),
  181. 'send_price' => sprintf('%.2f', 0),
  182. 'address' => $this->address,
  183. 'level' => [],
  184. 'mch_list' => $mchList,
  185. 'integral'=>$this->integral,
  186. 'goods_card_list' => [],
  187. 'template_id' => $template_id
  188. ],
  189. ];
  190. }
  191. }