OrderController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatOrderCountClass;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizGhs\order\classes\StockWastageOrderClass;
  6. use bizHd\purchase\classes\PurchaseClass;
  7. use bizHd\purchase\services\PurchaseService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use bizGhs\custom\classes\CustomClass;
  10. use bizGhs\order\classes\OrderClass;
  11. use bizGhs\order\services\OrderService;
  12. use bizHd\saas\services\RegionService;
  13. use bizGhs\product\classes\ProductClass;
  14. use common\components\dada\dada;
  15. use common\components\dict;
  16. use common\components\dateUtil;
  17. use common\components\freight;
  18. use common\components\httpUtil;
  19. use Yii;
  20. use common\components\util;
  21. use bizGhs\order\classes\RefundOrderClass;
  22. class OrderController extends BaseController
  23. {
  24. public $guestAccess = ['create-order', 'order-relate', 'fast-pay'];
  25. //订单列表 ssh 2021.1.20
  26. public function actionList()
  27. {
  28. $get = Yii::$app->request->get();
  29. $status = $get['status'] ?? 0;
  30. if (!empty($status)) {
  31. $where['status'] = $status;
  32. }
  33. $where['sjId'] = $this->sjId;
  34. if (isset($get['shopId'])) {
  35. $shopId = $get['shopId'] ?? 0;
  36. if (!empty($shopId)) {
  37. $where['shopId'] = $this->shopId;
  38. }
  39. } else {
  40. $where['shopId'] = $this->shopId;
  41. }
  42. $searchTime = $get['searchTime'] ?? '';
  43. if (!empty($searchTime)) {
  44. $startTime = $get['startTime'] ?? '';
  45. $endTime = $get['endTime'] ?? '';
  46. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  47. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  48. }
  49. $name = $get['name'] ?? '';
  50. if (!empty($name)) {
  51. //订单编号
  52. if (strpos($name, 'XSD') === 0) {
  53. $where['orderSn'] = $name;
  54. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  55. $where['customNamePy'] = ['like', $name];
  56. } else {
  57. $where['customName'] = ['like', $name];
  58. }
  59. }
  60. $respond = OrderClass::getOrderList($where);
  61. $respond['shop'] = $this->shop;
  62. $respond['shopExt'] = $this->shopExt;
  63. util::success($respond);
  64. }
  65. //商城下单操作 ssh 2021.1.14
  66. public function actionCreateOrder()
  67. {
  68. $post = Yii::$app->request->post();
  69. $shopId = $this->shopId;
  70. $customId = $post['customId'] ?? 0;
  71. $post['customId'] = $customId;
  72. //开单必须选客户
  73. if (empty($customId)) {
  74. util::fail('请选择客户');
  75. }
  76. $custom = CustomClass::getCustom($customId);
  77. if (empty($custom)) {
  78. util::fail('请选客户哦');
  79. }
  80. CustomClass::valid($custom, $this->shopId);
  81. $post['ghsId'] = $custom['ghsId'] ?? 0;
  82. $post['customMobile'] = $custom['mobile'] ?? '';
  83. $customName = $custom['name'] ?? '';
  84. $post['customName'] = $customName;
  85. $post['customNamePy'] = $custom['py'] ?? '';
  86. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  87. $post['shopAdminId'] = $this->shopAdminId;
  88. $post['province'] = $custom['province'] ?? '';
  89. $post['city'] = $custom['city'] ?? '';
  90. $post['dist'] = $custom['dist'] ?? '';
  91. $post['address'] = $custom['address'] ?? '';
  92. $post['floor'] = $custom['floor'] ?? '';
  93. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  94. $post['showAddress'] = $custom['showAddress'] ?? '';
  95. $shopAdmin = $this->shopAdmin->attributes;
  96. $post['shopAdminName'] = $shopAdmin['name'] ?? '';
  97. $post['sjId'] = $this->sjId;
  98. $post['shopId'] = $shopId;
  99. $post['fromType'] = 1;
  100. $post['expressId'] = $post['expressId'] ?? 0;
  101. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  102. //PC端开单
  103. if (isset($post['clearType'])) {
  104. $clearType = $post['clearType'];
  105. if ($clearType == OrderClass::CLEAR_DEBT) {
  106. $post['debt'] = OrderClass::DEBT_YES;
  107. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  108. } else {
  109. $post['debt'] = OrderClass::DEBT_NO;
  110. }
  111. }
  112. //员工不能开已收款订单
  113. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  114. if ($debt == OrderClass::DEBT_NO) {
  115. $shopAdmin = $this->shopAdmin;
  116. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  117. util::fail('只能开欠款订单');
  118. }
  119. }
  120. //PC端开单
  121. if (isset($post['getType'])) {
  122. util::fail('PC端开单未开放');
  123. $getType = $post['getType'];
  124. //自取
  125. if ($getType == 1) {
  126. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  127. } else {
  128. //选择配送时,在发货时让商家自己再确认一下用什么方式
  129. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  130. }
  131. }
  132. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  133. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  134. $post['debt'] = OrderClass::DEBT_NO;
  135. }
  136. $productJson = $post['product'] ?? '';
  137. if (empty($productJson)) {
  138. util::fail('请选择花材');
  139. }
  140. $productList = json_decode($productJson, true);
  141. if (empty($productList)) {
  142. util::fail('请选择花材');
  143. }
  144. $connection = Yii::$app->db;//事务处理
  145. $transaction = $connection->beginTransaction();
  146. try {
  147. //判断花材有效性
  148. ProductClass::valid($productList, $this->shopId);
  149. $post['product'] = $productList;
  150. //商家开单订单有效期更长(30)天
  151. $validTime = dict::getDict('kd_order_valid');
  152. $current = time() + $validTime;
  153. $post['deadline'] = date("Y-m-d H:i:s", $current);
  154. $return = OrderService::createOrder($post, $custom);
  155. $transaction->commit();
  156. util::success($return);
  157. } catch (\Exception $e) {
  158. $transaction->rollBack();
  159. Yii::error("下单失败原因:" . $e->getMessage());
  160. util::fail('下单失败');
  161. }
  162. }
  163. //修改订单 ssh 20210810
  164. public function actionUpdateOrder()
  165. {
  166. $post = Yii::$app->request->post();
  167. //PC端开单
  168. if (isset($post['clearType'])) {
  169. $clearType = $post['clearType'];
  170. if ($clearType == OrderClass::CLEAR_DEBT) {
  171. $post['debt'] = OrderClass::DEBT_YES;
  172. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  173. } else {
  174. $post['debt'] = OrderClass::DEBT_NO;
  175. }
  176. }
  177. //员工不能开已收款订单
  178. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  179. if ($debt == OrderClass::DEBT_NO) {
  180. $shopAdmin = $this->shopAdmin;
  181. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  182. util::fail('不能开已收款订单');
  183. }
  184. }
  185. //PC端开单
  186. if (isset($post['getType'])) {
  187. util::fail('暂不支持PC端修改订单');
  188. $getType = $post['getType'];
  189. //自取
  190. if ($getType == 1) {
  191. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  192. } else {
  193. //选择配送时,在发货时让商家自己再确认一下用什么方式
  194. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  195. }
  196. }
  197. $id = $post['id'] ?? 0;
  198. $order = OrderClass::getLockById($id);
  199. if (empty($order)) {
  200. util::fail('没有找到订单');
  201. }
  202. OrderClass::valid($order, $this->shopId);
  203. unset($post['id']);
  204. $shopAdmin = $this->shopAdmin;
  205. $post['shopAdminId'] = $this->shopAdminId;
  206. $post['shopAdminName'] = $shopAdmin->name ?? '';
  207. $post['fromType'] = 1;
  208. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  209. $productJson = $post['product'] ?? '';
  210. if (empty($productJson)) {
  211. util::fail('请选择花材');
  212. }
  213. $productList = json_decode($productJson, true);
  214. if (empty($productList)) {
  215. util::fail('请选择花材');
  216. }
  217. $connection = Yii::$app->db;//事务处理
  218. $transaction = $connection->beginTransaction();
  219. try {
  220. //判断花材有效性
  221. ProductClass::valid($productList, $this->shopId);
  222. $post['product'] = $productList;
  223. //商家开单订单有效期更长(30)天
  224. $validTime = dict::getDict('kd_order_valid');
  225. $current = time() + $validTime;
  226. $post['deadline'] = date("Y-m-d H:i:s", $current);
  227. $upData = [
  228. 'payWay' => $post['payWay'],
  229. 'sendType' => $post['sendType'],
  230. 'debt' => $post['debt'],
  231. 'needPrint' => $post['needPrint'],
  232. 'modifyPrice' => $post['modifyPrice'],
  233. 'shopAdminId' => $post['shopAdminId'],
  234. 'shopAdminName' => $post['shopAdminName'],
  235. 'fromType' => 1,
  236. 'sendCost' => $post['sendCost'],
  237. 'product' => $post['product'],
  238. 'deadline' => $post['deadline'],
  239. ];
  240. $return = OrderService::updateOrder($order, $upData);
  241. $transaction->commit();
  242. util::success($return);
  243. } catch (\Exception $e) {
  244. $transaction->rollBack();
  245. Yii::error("下单失败原因:" . $e->getMessage());
  246. util::fail('下单失败');
  247. }
  248. }
  249. //延期支付 ssh 2021.1.19
  250. public function actionDebt()
  251. {
  252. $get = Yii::$app->request->get();
  253. $id = $get['id'] ?? 0;
  254. $info = OrderService::getOrderInfo($id);
  255. OrderClass::valid($info, $this->shopId);
  256. OrderClass::debt($info, $this->shop);
  257. util::complete();
  258. }
  259. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  260. public function actionWxPay()
  261. {
  262. ini_set('date.timezone', 'Asia/Shanghai');
  263. $post = Yii::$app->request->post();
  264. $couponId = $post['couponId'] ?? 0;
  265. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  266. $order = OrderClass::getByOrderSn($orderSn);
  267. if (empty($order)) {
  268. util::fail('订单号无效');
  269. }
  270. $id = $order['id'];
  271. //支付前验证订单有效性
  272. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  273. util::fail('没有权限操作');
  274. }
  275. $name = $order['orderName'] ?? '购买商品';
  276. $totalFee = $order['actPrice'];
  277. //强制使用小程序的miniOpenId
  278. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  279. if (empty($openId)) {
  280. util::fail('没有找到openId');
  281. }
  282. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  283. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  284. $wxPayType = 0;
  285. if (httpUtil::isMiniProgram()) {
  286. $wxPayType = 1;
  287. }
  288. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  289. //订单30分钟后过期
  290. $now = time();
  291. $expireTime = $now + 1800;
  292. $wx = Yii::getAlias("@vendor/weixin");
  293. require_once($wx . '/lib/WxPay.Api.php');
  294. require_once($wx . '/example/WxPay.JsApiPay.php');
  295. $input = new \WxPayUnifiedOrder();
  296. $input->SetBody($name);
  297. $input->SetOut_trade_no($orderSn);
  298. $input->SetTotal_fee($totalFee * 100);
  299. $input->SetTime_start(date("YmdHis", $now));
  300. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  301. $input->SetTime_expire(date("YmdHis", $expireTime));
  302. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  303. $input->SetTrade_type("JSAPI");
  304. //花卉宝代为申请的微信支付
  305. //$merchantExtend = $this->sjExtend->attributes;
  306. $merchantExtend = WxOpenClass::getGhsWxInfo();
  307. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  308. $input->SetSub_openid($openId);
  309. } else {
  310. $input->SetOpenid($openId);
  311. }
  312. //强制使用小程序的miniAppId
  313. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  314. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  315. $tools = new \JsApiPay();
  316. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  317. $newParams = json_decode($jsApiParameters, true);
  318. //微信不能修改价格
  319. $current = date("Y-m-d H:i:s");
  320. $updateData = ['deadline' => $current, 'modPrice' => 0];
  321. OrderClass::updateById($id, $updateData);
  322. util::success($newParams);
  323. }
  324. //获取订单详情 ssh 2021.1.21
  325. public function actionDetail()
  326. {
  327. $get = Yii::$app->request->get();
  328. $id = $get['id'] ?? 0;
  329. $info = OrderService::getOrderInfo($id, true, true, true, false);
  330. OrderClass::valid($info, $this->shopId);
  331. //是否有云打印判断
  332. $hasCloudPrint = 0;
  333. $shopExt = $this->shopExt;
  334. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  335. $hasCloudPrint = 1;
  336. }
  337. $info['hasCloudPrint'] = $hasCloudPrint;
  338. util::success($info);
  339. }
  340. //自取免发货流程处理 ssh 2021.1.22
  341. public function actionWithoutSend()
  342. {
  343. $get = Yii::$app->request->get();
  344. $id = $get['id'] ?? 0;
  345. $info = OrderService::getById($id, true);
  346. OrderClass::valid($info, $this->shopId);
  347. $purchaseId = $info->purchaseId;
  348. $purchase = PurchaseClass::getById($purchaseId, true);
  349. OrderService::withoutSend($info, $purchase);
  350. util::complete();
  351. }
  352. //本店送 ssh 2021.1.24
  353. public function actionSelfSend()
  354. {
  355. $get = Yii::$app->request->get();
  356. $id = isset($get['id']) ? $get['id'] : 0;
  357. $info = OrderClass::getById($id, true);
  358. OrderClass::valid($info->attributes, $this->shopId);
  359. $connection = Yii::$app->db;
  360. $transaction = $connection->beginTransaction();
  361. try {
  362. OrderClass::selfSend($info);
  363. $transaction->commit();
  364. } catch (\Exception $exception) {
  365. $transaction->rollBack();
  366. Yii::info("本店送操作报错:" . $exception->getMessage());
  367. util::fail('操作失败');
  368. }
  369. util::complete();
  370. }
  371. //运费计算 ssh 2021.1.24
  372. public function actionFreight()
  373. {
  374. //2021.3.28 接入达达
  375. $get = Yii::$app->request->get();
  376. $post = Yii::$app->request->post();
  377. if (empty($get)) {
  378. $get = $post;
  379. }
  380. $orderId = $get['id'] ?? 0; //订单ID
  381. $customId = $get['customId'] ?? 0;
  382. if (empty($orderId)) {
  383. //自定义运费
  384. //freight::getCost();
  385. if (empty($customId)) {
  386. util::fail("请选择客户");
  387. }
  388. $customInfo = CustomClass::getById($customId);
  389. if (empty($customInfo)) {
  390. util::fail('没有找到客户');
  391. }
  392. $shop = $this->shop;
  393. //花材信息
  394. $productJson = $get['product'] ?? '';
  395. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  396. if (empty($productJson)) {
  397. util::fail('请选择花材');
  398. }
  399. $productList = json_decode($productJson, true);
  400. if (empty($productList)) {
  401. util::fail('请选择花材');
  402. }
  403. $productList = ProductClass::mergeItemInfo($productList);
  404. $weight = 0;
  405. $price = 0;
  406. $productData = ProductClass::getProductMapData($productList);
  407. $bigNum = 0;
  408. foreach ($productList as $key => $val) {
  409. $productId = $val['productId'];
  410. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  411. $bigNum += $val['bigNum'];
  412. $weight = bcadd($w, $weight, 2);
  413. $ratio = $productData[$productId]['ratio'] ?? 0;
  414. //大小数量合并多少扎
  415. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  416. //售卖价格
  417. $itemPrice = $productData[$productId]['price'] ?? 0;
  418. //合计价格
  419. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  420. }
  421. //没有经纬度的客户运费直接返回空 shish 20210612
  422. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  423. util::success(['sedCost' => '']);
  424. }
  425. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  426. util::success(['sedCost' => $cost]);
  427. }
  428. $province = $get['province'] ?? '';
  429. $city = $get['city'] ?? '';
  430. $address = $get['address'] ?? '';
  431. $floor = $get['floor'] ?? '';
  432. $customName = $get['customName'] ?? '';
  433. $customMobile = $get['customMobile'] ?? '';
  434. $fullAddress = $province . $city . $address . $floor;
  435. $sendTime = $get['sendTime'] ?? '';
  436. $lat = $get['lat'] ?? '';
  437. $lng = $get['long'] ?? '';
  438. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  439. util::fail('请填写客户地址');
  440. }
  441. ini_set('date.timezone', 'Asia/Shanghai');
  442. if (!empty($sendTime)) {
  443. //配送时间不为空
  444. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  445. $sendTimeInt = strtotime($sendTime);
  446. $now = time();
  447. $diff = $sendTimeInt - $now;
  448. //因服务器写入时间,改为至少提前6分钟
  449. if ($diff <= 360) {
  450. util::fail('配送时间至少提前6分钟');
  451. }
  452. } else {
  453. //默认立即发送
  454. $sendTime = 0;
  455. }
  456. //更新订单表
  457. $info = OrderService::getOrderInfo($orderId);
  458. OrderClass::valid($info, $this->shopId);
  459. if ($sendTime) {
  460. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  461. } else {
  462. $sendTime = '0000-00-00 00:00:00';
  463. }
  464. $expressAddInfo = [
  465. 'customName' => $customName,
  466. 'customMobile' => $customMobile,
  467. 'province' => $province,
  468. 'city' => $city,
  469. 'address' => $address,
  470. 'floor' => $floor,
  471. 'lat' => $lat,
  472. 'long' => $lng,
  473. 'sendTime' => $sendTime,
  474. ];
  475. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  476. //计算运费
  477. $info['province'] = $province;
  478. $info['city'] = $city;
  479. $info['address'] = $address;
  480. $info['floor'] = $floor;
  481. $info['fullAddress'] = $fullAddress;
  482. $info['lat'] = $lat;
  483. $info['long'] = $lng;
  484. $info['sendTime'] = $expressAddInfo['sendTime'];
  485. $res = DadaExpressServices::queryDeliverFee($info);
  486. util::success(['sedCost' => $res['fee']]);
  487. }
  488. //发快递和第三方配送 ssh 2021.1.24
  489. public function actionThirdSend()
  490. {
  491. $get = Yii::$app->request->get();
  492. $id = isset($get['id']) ? $get['id'] : 0;
  493. $info = OrderService::getById($id, true);
  494. OrderClass::valid($info->attributes, $this->shopId);
  495. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  496. util::fail('请填写客户地址');
  497. }
  498. $connection = Yii::$app->db;
  499. $transaction = $connection->beginTransaction();
  500. try {
  501. $respond = OrderClass::thirdSend($info, $get);
  502. $transaction->commit();
  503. util::success($respond);
  504. } catch (\Exception $exception) {
  505. $transaction->rollBack();
  506. Yii::info("发快递操作报错:" . $exception->getMessage());
  507. util::fail('操作失败' . $exception->getMessage());
  508. }
  509. }
  510. //确认送达 ssh 2021.1.24
  511. public function actionReach()
  512. {
  513. $get = Yii::$app->request->get();
  514. $id = isset($get['id']) ? $get['id'] : 0;
  515. $info = OrderClass::getById($id, true);
  516. OrderClass::valid($info->attributes, $this->shopId);
  517. $connection = Yii::$app->db;
  518. $transaction = $connection->beginTransaction();
  519. try {
  520. OrderService::reach($info);
  521. $transaction->commit();
  522. } catch (\Exception $exception) {
  523. $transaction->rollBack();
  524. Yii::info("送达操作报错:" . $exception->getMessage());
  525. util::fail('操作失败');
  526. }
  527. util::complete();
  528. }
  529. //下单要用到的相关信息 ssh 2019.12.6
  530. public function actionOrderRelate()
  531. {
  532. $regionTree = RegionService::tree();
  533. $shop = $this->shop->attributes;
  534. $freight = ['first' => 5, 'add' => 2];
  535. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  536. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  537. util::success($out);
  538. }
  539. //客户欠款的订单 ssh 2021.2.4
  540. public function actionDebtList()
  541. {
  542. $id = Yii::$app->request->get('id', 0);
  543. $info = CustomClass::getCustom($id);
  544. CustomClass::valid($info, $this->shopId);
  545. $where = ['customId' => $id, 'debt' => 1];
  546. $respond = OrderService::getDebtOrderList($where);
  547. $respond['customInfo'] = $info;
  548. util::success($respond);
  549. }
  550. //更新打印次数
  551. public function actionAddPrintNum()
  552. {
  553. $id = Yii::$app->request->get('id', 0);
  554. $order = OrderClass::getById($id, true);
  555. OrderClass::valid($order, $this->shopId);
  556. $order->printNum += 1;
  557. $order->save();
  558. util::complete();
  559. }
  560. //打印订单 shish 20210714
  561. public function actionCloudPrintOrder()
  562. {
  563. $id = Yii::$app->request->get('id', 0);
  564. $order = OrderClass::getById($id, true);
  565. OrderClass::valid($order, $this->shopId);
  566. //打印订单
  567. OrderClass::onlinePrint($order);
  568. $order->printNum += 1;
  569. $order->save();
  570. util::complete();
  571. }
  572. //订单确认完成 shish 20210809
  573. public function actionConfirmFinish()
  574. {
  575. $payWay = Yii::$app->request->get('payWay', -1);
  576. $id = Yii::$app->request->get('id', 0);
  577. $clearType = Yii::$app->request->get('clearType', 0);
  578. $connection = Yii::$app->db;
  579. $transaction = $connection->beginTransaction();
  580. try {
  581. $order = OrderClass::getById($id, true);
  582. OrderClass::valid($order, $this->shopId);
  583. $purchaseId = $order->purchaseId ?? 0;
  584. $purchase = PurchaseClass::getById($purchaseId, true);
  585. if (empty($purchase)) {
  586. util::fail('没有采购信息');
  587. }
  588. if ($clearType == 1) {
  589. //欠款
  590. $payWay = dict::getDict('payWay', 'debtPay');
  591. } elseif ($clearType == 2) {
  592. //已收款
  593. if ($payWay == -1) {
  594. util::fail('请选择收款方式');
  595. }
  596. } else {
  597. util::fail('请选择结算方式');
  598. }
  599. //不需要打印
  600. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  601. $order->save();
  602. //支付
  603. PurchaseService::payAfter($purchase, $payWay);
  604. OrderService::payAfter($order, $payWay);
  605. //自己送
  606. $info = OrderClass::getById($id, true);
  607. OrderClass::selfSend($info);
  608. //确认送达,并且不需要微信通知
  609. Yii::$app->params['noNeedWxNotice'] = 1;
  610. $info = OrderClass::getById($id, true);
  611. OrderService::reach($info);
  612. $transaction->commit();
  613. util::complete('操作成功');
  614. } catch (\Exception $exception) {
  615. $transaction->rollBack();
  616. Yii::info("确认完成订单报错:" . $exception->getMessage());
  617. util::fail('操作失败');
  618. }
  619. }
  620. //取消订单 shish 20210810
  621. public function actionCancel()
  622. {
  623. $id = Yii::$app->request->get('id', 0);
  624. $order = OrderClass::getById($id, true);
  625. OrderClass::valid($order, $this->shopId);
  626. OrderClass::cancel($id);
  627. util::complete();
  628. }
  629. }