OrderSubmitPreviewForm.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\models\order;
  8. use app\constants\OptionSetting;
  9. use app\models\District;
  10. use app\models\FoodFlag;
  11. use app\models\Goods;
  12. use app\models\Md;
  13. use app\models\Option;
  14. use app\models\SaasUser;
  15. use app\models\Store;
  16. use app\models\User;
  17. use app\utils\Delivery\Delivery;
  18. use app\utils\Notice\NoticeAction;
  19. use app\utils\OrderNo;
  20. use app\utils\Tools;
  21. use yii\helpers\Json;
  22. class OrderSubmitPreviewForm extends OrderForm
  23. {
  24. public function rules()
  25. {
  26. return parent::rules();
  27. }
  28. public function search()
  29. {
  30. if (!$this->validate())
  31. return [
  32. 'code' => 1,
  33. 'msg' => $this->getErrorSummary(false)[0],
  34. ];
  35. // HKG 新增判断商城打烊状态 开始
  36. if(get_store_id() > 0 && Option::get(OptionSetting::MALL_STATUS,get_store_id(),'store',0)['value'] == 1)
  37. return [
  38. 'code' => 1,
  39. 'msg' => '商城已打烊~'
  40. ];
  41. // HKG 新增判断商城打烊状态 结束
  42. try {
  43. // 预生成订单号
  44. $order_no = OrderNo::getOrderNo(OrderNo::ORDER_ALLIANCE);
  45. cache()->set('delivery_order_no_' . get_saas_user_id(), $order_no);
  46. $storeList = $this->getStoreListData();
  47. if(isset($storeList['code']) && $storeList['code'] == 1){
  48. return $storeList;
  49. }
  50. } catch(\Exception $e) {
  51. return [
  52. 'code' => 1,
  53. 'line' => $e->getLine(),
  54. 'msg' => $e->getMessage(),
  55. 'file' => $e->getFile(),
  56. ];
  57. }
  58. $food_pay_type = $store_info = [];
  59. $flag_id = 0;
  60. $store = Store::findOne(get_store_id());
  61. if (get_md_id() && (!empty(input_params('flag_id')) || !empty(input_params('table_num')))) {
  62. if (!empty(input_params('flag_id'))) {
  63. $flag_id = input_params('flag_id');
  64. } else {
  65. $flag_id = FoodFlag::findOne(['store_id' => get_store_id(), 'status' => 0, 'table_num' => input_params('table_num')])->id;
  66. }
  67. $food_payment = $store->food_payment;
  68. $food_paytype = $store->food_pay_type;
  69. $food_pay_list = [];
  70. if (!empty($food_payment)) {
  71. $food_pay_type = Json::decode($food_payment);
  72. // $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store');
  73. // $is_food_ok = false;
  74. // if (!empty($pay_type_list_json)) {
  75. // $pay_type_list = Json::decode($pay_type_list_json['value']);
  76. // foreach ($pay_type_list as $index => $pay_type) {
  77. // if ($index == 'friend' && $pay_type['value'] == 1) {
  78. // $is_food_ok = true;
  79. // break;
  80. // }
  81. // }
  82. // }
  83. foreach ($food_pay_type as &$value) {
  84. // if ($value['key'] == 'friend') {
  85. // if ($is_food_ok && $value['value'] == 1) {
  86. // $value['value'] = 1;
  87. // } else {
  88. // $value['value'] = 0;
  89. // }
  90. // }
  91. if ($value['key'] == 'friend') {
  92. $value['payment'] = 7;
  93. if(!$value['name']){
  94. $value['name'] = "朋友代付";
  95. }
  96. }
  97. if ($value['key'] == 'alipay') {
  98. $value['payment'] = 4;
  99. if(!$value['name']){
  100. $value['name'] = "支付宝支付";
  101. }
  102. }
  103. if ($value['key'] == 'wechat') {
  104. $value['payment'] = 1;
  105. if(!$value['name']){
  106. $value['name'] = "微信支付";
  107. }
  108. }
  109. if ($value['key'] == 'huodao') {
  110. $value['payment'] = 2;
  111. if(!$value['name']){
  112. $value['name'] = "货到付款";
  113. }
  114. }
  115. }
  116. $food_pay_list = $food_pay_type;
  117. }
  118. foreach ($food_pay_list as $k => $val) {
  119. if (($val['payment'] == 4 && is_wechat_platform()) || ($val['payment'] == 4 && intval($val['value']) === 0)) {
  120. unset($food_pay_list[$k]);
  121. }
  122. if (($val['payment'] == 1 && is_alipay_platform()) || ($val['payment'] == 1 && intval($val['value']) === 0)) {
  123. unset($food_pay_list[$k]);
  124. }
  125. if ($val['payment'] == 7 && intval($val['value']) === 0) {
  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. $province_name = isset(District::findOne($store->province_id)->name) ? District::findOne($store->province_id)->name : '';
  137. $city_name = isset(District::findOne($store->city_id)->name) ? District::findOne($store->city_id)->name : '';
  138. $district_name = isset(District::findOne($store->district_id)->name) ? District::findOne($store->district_id)->name : '';
  139. list($lat, $long) = explode(',', empty($store->coordinate) ? ',' : $store->coordinate);
  140. $store_info = [
  141. 'name' => $store->name,
  142. 'detail_address' => $province_name . $city_name . $district_name . $store->address,
  143. 'distance' => Tools::getDistance($this->latitude, $this->longitude, $lat, $long),
  144. 'longitude' => $long,
  145. 'latitude' => $lat,
  146. 'logo' => $store->logo
  147. ];
  148. //计算联盟券
  149. $take_price = 0;
  150. $send_price = 0;
  151. $user_league_price = \get_saas_user()->league_price ?? 0;
  152. // $send_profit_model = Option::findOne(['name' => 'store_send_profit']);//平台让利比例
  153. // $this_store_send_profit_model= Option::findOne(['name' => 'store_this_profit','store_id' => get_store_id()]);
  154. // if($this_store_send_profit_model->value > 0){
  155. // $basic_send_profit = $this_store_send_profit_model->value;
  156. // }else{
  157. // $basic_send_profit = $send_profit_model->value;
  158. // }
  159. foreach ($storeList[0]['goods_list'] as &$arr) {
  160. // $goods = Goods::findOne($arr['goods_id']);
  161. //TODO 新的
  162. //计算返利
  163. $send_price += $arr['send_price'] ?? 0;
  164. $take_price += $arr['take_price'] ?? 0;
  165. }
  166. $total_price = 0;
  167. foreach ($storeList as $store_item) {
  168. $total_price += $store_item['total_price'];
  169. }
  170. if (bcsub($total_price, $take_price, 2) <= 0) {
  171. $this->integral = 0;
  172. }
  173. return [
  174. 'code' => 0,
  175. 'msg' => 'OOKK',
  176. 'data' => [
  177. 'order_no' => $order_no,
  178. 'goods_send_profit' => 0,
  179. 'store_send_profit' => 0,
  180. 'flag_id' => intval($flag_id),
  181. 'store_info' => $store_info,
  182. 'food_pay' => $food_pay_type,
  183. 'pay_type_list' => $this->getPayTypeList(),
  184. 'address' => $this->address,
  185. 'take_price' => $take_price,
  186. 'send_price' => $send_price,
  187. 'user_league_price' => $user_league_price,
  188. //'level' => $this->getLevelData(),
  189. 'store_list' => $storeList,
  190. 'integral' => $this->integral,
  191. //'goods_card_list' => $this->goodsCardList(),
  192. 'template_id' => NoticeAction::getSendTamplateId(['order_pay', 'order_submit', 'order_send'])
  193. ],
  194. ];
  195. }
  196. }