OrderController.php 24 KB

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