OrderController.php 26 KB

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