StoreOrderController.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. <?php
  2. namespace app\api\controller\admin;
  3. use app\admin\model\order\StoreOrder as StoreOrderModel;
  4. use app\admin\model\system\SystemStoreBill;
  5. use app\admin\model\system\SystemStoreExtract;
  6. use app\admin\model\system\SystemStorePoint;
  7. use app\admin\model\system\SystemStoreProductStock;
  8. use app\admin\model\system\SystemStoreSender;
  9. use app\admin\model\user\UserRecharge;
  10. use app\models\system\SystemStore;
  11. use app\Request;
  12. use crmeb\basic\BaseModel;
  13. use think\db\exception\DataNotFoundException;
  14. use think\db\exception\DbException;
  15. use think\db\exception\ModelNotFoundException;
  16. use app\models\user\{
  17. User, UserBill
  18. };
  19. use crmeb\repositories\OrderRepository;
  20. use crmeb\repositories\ShortLetterRepositories;
  21. use crmeb\services\{
  22. MiniProgramService, UtilService, WechatService
  23. };
  24. use app\models\store\{Card, StoreCart, StoreExchangeOrder, StoreOrder, StoreOrderStatus, StorePink, StoreService};
  25. use app\models\system\SystemStoreStaff;
  26. /**
  27. * 订单类
  28. * Class StoreOrderController
  29. * @package app\api\controller\admin\order
  30. */
  31. class StoreOrderController
  32. {
  33. public function pointList(Request $request)
  34. {
  35. $uid = $request->uid();
  36. $where = UtilService::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ['type', 1]
  40. ]);
  41. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  42. if (!$info) {
  43. return app('json')->fail('权限不足');
  44. }
  45. // var_dump($info->toArray());
  46. $where['store_id'] = $info['store_id'];
  47. $where['excel'] = 0;
  48. // $where['type'] = $info['store_id'];
  49. return app('json')->successful('ok', SystemStorePoint::getStoreList($where));
  50. }
  51. public function senderList(Request $request)
  52. {
  53. $uid = $request->uid();
  54. $where = UtilService::getMore([
  55. ['page', 1],
  56. ['limit', 20],
  57. ]);
  58. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  59. if (!$info) {
  60. return app('json')->fail('权限不足');
  61. }
  62. // var_dump($info->toArray());
  63. $where['store_id'] = $info['store_id'];
  64. $where['excel'] = 0;
  65. // $where['type'] = $info['store_id'];
  66. return app('json')->successful('ok', SystemStoreSender::getStoreList($where));
  67. }
  68. public function pointDetail($id, Request $request)
  69. {
  70. $uid = $request->uid();
  71. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  72. if (!$info) {
  73. return app('json')->fail('权限不足');
  74. }
  75. return app('json')->successful('ok', ['data' => SystemStorePoint::getStoreDispose($id)]);
  76. }
  77. public function sendCard(Request $request)
  78. {
  79. $uid = $request->uid();
  80. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  81. if (!$info) {
  82. return app('json')->fail('权限不足');
  83. }
  84. $code = UtilService::postMore(['code']);
  85. $res = Card::sendCard($info['store_id'], $code);
  86. if ($res)
  87. return app('json')->successful('赠送成功');
  88. else return app('json')->fail(Card::getErrorInfo('赠送失败'));
  89. }
  90. public function checkCard(Request $request)
  91. {
  92. $uid = $request->uid();
  93. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  94. if (!$info) {
  95. return app('json')->fail('权限不足');
  96. }
  97. $code = UtilService::postMore(['code', 'password']);
  98. $res = Card::checkCard($info['store_id'], $code['code'], $code['password']);
  99. if ($res)
  100. return app('json')->successful('核销成功');
  101. else return app('json')->fail(Card::getErrorInfo('核销失败'));
  102. }
  103. public function addDetail(Request $request, $id = 0)
  104. {
  105. $uid = $request->uid();
  106. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  107. if (!$info) {
  108. return app('json')->fail('权限不足');
  109. }
  110. $data = UtilService::postMore([
  111. ['name', ''],
  112. ['phone', ''],
  113. ['address', ''],
  114. ['detailed_address', ''],
  115. ['latlng', ''],
  116. ['valid_time', []],
  117. ['day_time', []],
  118. ['is_show', 0],
  119. ]);
  120. $data['store_id'] = $info['store_id'];
  121. $data['address'] = implode(',', $data['address']);
  122. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  123. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return app('json')->fail('请选择门店位置');
  124. $data['latitude'] = $data['latlng'][0];
  125. $data['longitude'] = $data['latlng'][1];
  126. $data['valid_time'] = implode(' - ', $data['valid_time']);
  127. $data['day_time'] = implode(' - ', $data['day_time']);
  128. unset($data['latlng']);
  129. if ($id) {
  130. $store_info = SystemStorePoint::get($id);
  131. if ($store_info['store_id'] != $info['store_id']) {
  132. return app('json')->fail('权限不足');
  133. }
  134. if (SystemStorePoint::where('id', $id)->update($data)) {
  135. SystemStorePoint::commitTrans();
  136. return app('json')->successful('修改成功');
  137. } else {
  138. SystemStorePoint::rollbackTrans();
  139. return app('json')->fail('修改失败或者您没有修改什么!');
  140. }
  141. } else {
  142. $data['add_time'] = time();
  143. $data['is_show'] = 1;
  144. if ($res = SystemStorePoint::create($data)) {
  145. SystemStorePoint::commitTrans();
  146. return app('json')->successful('保存成功', ['id' => $res->id]);
  147. } else {
  148. SystemStorePoint::rollbackTrans();
  149. return app('json')->fail('保存失败!');
  150. }
  151. }
  152. }
  153. /**
  154. * 删除恢复门店
  155. * @param $id
  156. */
  157. public function point_delete($id, Request $request)
  158. {
  159. if (!$id) return app('json')->fail('数据不存在');
  160. if (!SystemStorePoint::be(['id' => $id])) return app('json')->fail('数据不存在');
  161. $uid = $request->uid();
  162. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  163. if (!$info) {
  164. return app('json')->fail('权限不足');
  165. }
  166. $store_info = SystemStorePoint::get($id);
  167. if ($store_info['store_id'] != $info['store_id']) {
  168. return app('json')->fail('权限不足');
  169. }
  170. if (SystemStorePoint::be(['id' => $id, 'is_del' => 1])) {
  171. $data['is_del'] = 0;
  172. if (!SystemStorePoint::edit($data, $id))
  173. return app('json')->fail(SystemStorePoint::getErrorInfo('恢复失败,请稍候再试!'));
  174. else
  175. return app('json')->success('恢复门店成功!');
  176. } else {
  177. $data['is_del'] = 1;
  178. if (!SystemStorePoint::edit($data, $id))
  179. return app('json')->fail(SystemStorePoint::getErrorInfo('删除失败,请稍候再试!'));
  180. else
  181. return app('json')->success('删除门店成功!');
  182. }
  183. }
  184. public function stockList(Request $request)
  185. {
  186. $uid = $request->uid();
  187. $where = UtilService::getMore([
  188. ['type', ''],
  189. ['page', 1],
  190. ['limit', 20],
  191. ['start_time', ''],
  192. ['end_time', ''],
  193. ]);
  194. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  195. if (!$info) {
  196. return app('json')->fail('权限不足');
  197. }
  198. return app('json')->successful('ok', ['warning' => SystemStoreProductStock::getWarning($info['store_id']), 'data' => SystemStoreProductStock::getStockList($where, $info['store_id'])]);
  199. }
  200. public function billList(Request $request)
  201. {
  202. $uid = $request->uid();
  203. $where = UtilService::getMore([
  204. ['page', 1],
  205. ['limit', 20],
  206. ['type', ''],
  207. ['time', ''],
  208. ]);
  209. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  210. if (!$info) {
  211. return app('json')->fail('权限不足');
  212. }
  213. return app('json')->successful('ok', ['switch' => sys_config('withdraw_switch', 0), 'all' => SystemStore::get($info['store_id'])['brokerage_price'], 'data' => SystemStoreBill::getList($where, $info['store_id'])]);
  214. }
  215. public function cash(Request $request)
  216. {
  217. $uid = $request->uid();
  218. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  219. if (!$info) {
  220. return app('json')->fail('权限不足');
  221. }
  222. if (!in_array(sys_config('default_store_admin', 7), explode(',', $request->admin_info()['roles']))) {
  223. return app('json')->fail('权限不足');
  224. }
  225. $store = SystemStore::get($info['store_id']);
  226. $extractInfo = UtilService::postMore([
  227. ['money', 0],
  228. ['bankname', ''],
  229. ['name', ''],
  230. ['cardnum', ''],
  231. ], $request);
  232. $extractInfo['extract_type'] = 'bank';
  233. $extractInfo['name'] = $extractInfo['name'] ?? $store['leader'];
  234. if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) app('json')->fail('提现金额输入有误');
  235. $store = SystemStore::get($info['store_id']);
  236. if ($extractInfo['money'] > $store['brokerage_price']) return app('json')->fail('可提现佣金不足');
  237. if (!$extractInfo['cardnum'] == '')
  238. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  239. return app('json')->fail('银行卡号有误');
  240. if (SystemStoreExtract::userExtract($store, $extractInfo))
  241. return app('json')->successful('申请提现成功!');
  242. else
  243. return app('json')->fail(SystemStoreExtract::getErrorInfo('提现失败'));
  244. }
  245. public function childrenList(Request $request)
  246. {
  247. $uid = $request->uid();
  248. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  249. if (!$info) {
  250. return app('json')->fail('权限不足');
  251. }
  252. $where = UtilService::getMore([
  253. ['page', 1],
  254. ['limit', 20],
  255. ['name', ''],
  256. ['level', ''],
  257. ['excel', 0],
  258. ['type', ''],
  259. ['parent_id', 0],
  260. ]);
  261. $where['self_store'] = $info['store_id'];
  262. return app('json')->successful('ok', \app\admin\model\system\SystemStore::getStoreList($where));
  263. }
  264. /**
  265. * 订单数据统计
  266. * @param Request $request
  267. * @return mixed
  268. * @throws DataNotFoundException
  269. * @throws DbException
  270. * @throws ModelNotFoundException
  271. */
  272. public function statistics(Request $request)
  273. {
  274. $uid = $request->uid();
  275. // if (!StoreService::orderServiceStatus($uid))
  276. // return app('json')->fail('权限不足');
  277. $where = [];
  278. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  279. if ($info) {
  280. $where['store_id'] = $info['store_id'];
  281. }
  282. $dataCount = StoreOrder::getOrderDataAdmin($where);
  283. $dataPrice = StoreOrder::getOrderTimeData($where);
  284. $data = array_merge($dataCount, $dataPrice);
  285. return app('json')->successful($data);
  286. }
  287. /**
  288. * 订单每月统计数据
  289. * @param Request $request
  290. * @return mixed
  291. * @throws DataNotFoundException
  292. * @throws DbException
  293. * @throws ModelNotFoundException
  294. */
  295. public function data(Request $request)
  296. {
  297. $uid = $request->uid();
  298. // if (!StoreService::orderServiceStatus($uid))
  299. // return app('json')->fail('权限不足');
  300. list($page, $limit, $start, $stop) = UtilService::getMore([
  301. ['page', 1],
  302. ['limit', 7],
  303. ['start', ''],
  304. ['stop', '']
  305. ], $request, true);
  306. $where = [];
  307. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  308. if ($info) {
  309. $where['store_id'] = $info['store_id'];
  310. }
  311. if (!$limit) return app('json')->successful([]);
  312. $data = StoreOrder::getOrderDataPriceCount($page, $limit, $start, $stop, $where);
  313. if ($data) return app('json')->successful($data->toArray());
  314. return app('json')->successful([]);
  315. }
  316. /**
  317. * 订单列表
  318. * @param Request $request
  319. * @return mixed
  320. * @throws DataNotFoundException
  321. * @throws DbException
  322. * @throws ModelNotFoundException
  323. */
  324. public function lst(Request $request)
  325. {
  326. $uid = $request->uid();
  327. // if (!StoreService::orderServiceStatus($uid))
  328. // return app('json')->fail('权限不足');
  329. $where = UtilService::getMore([
  330. ['status', ''],
  331. ['user_phone', ''],
  332. ['is_del', 0],
  333. ['data', ''],
  334. ['type', ''],
  335. ['shipping_type', ''],
  336. ['order', ''],
  337. ['page', 0],
  338. ['limit', 0]
  339. ], $request);
  340. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  341. if ($info) {
  342. $where['store_id'] = $info['store_id'];
  343. }
  344. if (!$where['limit']) return app('json')->successful([]);
  345. return app('json')->successful(StoreOrder::orderList($where));
  346. }
  347. /**
  348. * 订单列表
  349. * @param Request $request
  350. * @return mixed
  351. * @throws DataNotFoundException
  352. * @throws DbException
  353. * @throws ModelNotFoundException
  354. */
  355. public function exchange_order_lst(Request $request)
  356. {
  357. $uid = $request->uid();
  358. $where = UtilService::getMore([
  359. ['status', ''],
  360. ['user_phone', ''],
  361. ['is_del', 0],
  362. ['data', ''],
  363. ['order', ''],
  364. ['page', 0],
  365. ['limit', 0]
  366. ], $request);
  367. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  368. if ($info) {
  369. $where['store_id'] = $info['store_id'];
  370. }
  371. if (!$where['limit']) return app('json')->successful([]);
  372. return app('json')->successful(StoreExchangeOrder::orderList($where));
  373. }
  374. /**
  375. * 订单详情
  376. * @param Request $request
  377. * @param $orderId
  378. * @return mixed
  379. * @throws DataNotFoundException
  380. * @throws ModelNotFoundException
  381. * @throws DbException
  382. */
  383. public function detail(Request $request, $orderId)
  384. {
  385. $uid = $request->uid();
  386. // if (!StoreService::orderServiceStatus($uid))
  387. // return app('json')->fail('权限不足');
  388. $where = [];
  389. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  390. if ($info) {
  391. $where['store_id'] = $info['store_id'];
  392. }
  393. $order = StoreOrder::getAdminOrderDetail($orderId, 'id,uid,order_id,add_time,status,total_num,total_price,total_postage,pay_price,pay_postage,paid,refund_status,remark,pink_id,combination_id,mark,seckill_id,bargain_id,delivery_type,pay_type,real_name,user_phone,user_address,coupon_price,freight_price,delivery_name,delivery_type,delivery_id,store_id,point_id', $where);
  394. if (!$order) return app('json')->fail('订单不存在');
  395. $order = $order->toArray();
  396. $nickname = User::getUserInfo($order['uid'], 'nickname')['nickname'];
  397. $orderInfo = StoreOrder::tidyAdminOrder([$order], true)[0];
  398. unset($orderInfo['uid'], $orderInfo['seckill_id'], $orderInfo['pink_id'], $orderInfo['combination_id'], $orderInfo['bargain_id'], $orderInfo['status'], $orderInfo['total_postage']);
  399. $orderInfo['nickname'] = $nickname;
  400. return app('json')->successful('ok', $orderInfo);
  401. }
  402. /**
  403. * 订单发货获取订单信息
  404. * @param Request $request
  405. * @param $orderId
  406. * @return mixed
  407. * @throws DataNotFoundException
  408. * @throws ModelNotFoundException
  409. * @throws DbException
  410. */
  411. public function delivery_gain(Request $request, $orderId)
  412. {
  413. $uid = $request->uid();
  414. // if (!StoreService::orderServiceStatus($uid))
  415. // return app('json')->fail('权限不足');
  416. $where = [];
  417. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  418. if ($info) {
  419. $where['store_id'] = $info['store_id'];
  420. }
  421. $order = StoreOrder::getAdminOrderDetail($orderId, 'real_name,user_phone,user_address,order_id,uid,status,paid', $where);
  422. if (!$order) return app('json')->fail('订单不存在');
  423. if ($order['paid']) {
  424. $order['nickname'] = User::getUserInfo($order['uid'], 'nickname')['nickname'];
  425. $order = $order->hidden(['uid', 'status', 'paid'])->toArray();
  426. return app('json')->successful('ok', $order);
  427. }
  428. return app('json')->fail('状态错误');
  429. }
  430. /**
  431. * 订单发货
  432. * @param Request $request
  433. * @return mixed
  434. * @throws DataNotFoundException
  435. * @throws ModelNotFoundException
  436. * @throws \think\exception\DbException
  437. * @throws DbException
  438. */
  439. public function delivery_keep(Request $request)
  440. {
  441. $uid = $request->uid();
  442. // if (!StoreService::orderServiceStatus($uid))
  443. // return app('json')->fail('权限不足');
  444. list($order_id, $delivery_type, $delivery_name, $delivery_id) = UtilService::postMore([
  445. ['order_id', ''],
  446. ['delivery_type', 0],
  447. ['delivery_name', ''],
  448. ['delivery_id', ''],
  449. ], $request, true);
  450. $where = [];
  451. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  452. if ($info) {
  453. $where['store_id'] = $info['store_id'];
  454. }
  455. $order = StoreOrder::getAdminOrderDetail($order_id, 'id,status,paid', $where);
  456. if (!$order) return app('json')->fail('订单不存在');
  457. if (!$order['status'] && $order['paid']) {
  458. $deliveryTypeArr = isset($where['store_id']) ? ['send'] : ['send', 'express', 'fictitious'];
  459. if (!strlen(trim($delivery_type))) return app('json')->fail('请填写发货方式');
  460. if (!in_array($delivery_type, $deliveryTypeArr)) return app('json')->fail('发货方式错误');
  461. if ($delivery_type == 'express') {
  462. if (!strlen(trim($delivery_name))) return app('json')->fail('请选择快递公司');
  463. if (!strlen(trim($delivery_id))) return app('json')->fail('请填写快递单号');
  464. }
  465. if ($delivery_type == 'send') {
  466. if (!strlen(trim($delivery_name))) return app('json')->fail('请填写发货人');
  467. if (!strlen(trim($delivery_id))) return app('json')->fail('请填写发货手机号');
  468. }
  469. $data['status'] = 1;
  470. $data['delivery_type'] = $delivery_type;
  471. $data['delivery_name'] = $delivery_name;
  472. $data['delivery_id'] = $delivery_id;
  473. $res = StoreOrder::edit($data, $order['id'], 'id');
  474. if ($res) {
  475. if ($delivery_type == 'express') {
  476. StoreOrderStatus::status($order['id'], 'delivery_goods', '已发货 快递公司:' . $data['delivery_name'] . ' 快递单号:' . $data['delivery_id']);
  477. } else if ($delivery_type == 'send') {
  478. StoreOrderStatus::status($order['id'], 'delivery', '已配送 发货人:' . $delivery_name . ' 发货人电话:' . $delivery_id);
  479. } else if ($delivery_type == 'fictitious') {
  480. StoreOrderStatus::status($order['id'], 'delivery_fictitious', '虚拟产品已发货');
  481. }
  482. }
  483. event('StoreProductOrderDeliveryGoodsAfter', [$data, $order['id']]);
  484. return app('json')->successful('发货成功!');
  485. }
  486. return app('json')->fail('状态错误');
  487. }
  488. /**
  489. * 订单改价
  490. * @param Request $request
  491. * @return mixed
  492. * @throws DataNotFoundException
  493. * @throws ModelNotFoundException
  494. * @throws DbException
  495. */
  496. public function price(Request $request)
  497. {
  498. $uid = $request->uid();
  499. // if (!StoreService::orderServiceStatus($uid))
  500. // return app('json')->fail('权限不足');
  501. list($order_id, $price) = UtilService::postMore([
  502. ['order_id', ''],
  503. ['price', '']
  504. ], $request, true);
  505. $where = [];
  506. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  507. if ($info) {
  508. $where['store_id'] = $info['store_id'];
  509. }
  510. $order = StoreOrder::getAdminOrderDetail($order_id, 'id,paid,user_phone,pay_price,order_id,total_price,total_postage,pay_postage,gain_integral', $where);
  511. if (!$order) return app('json')->fail('订单不存在');
  512. $order = $order->toArray();
  513. if (!$order['paid']) {
  514. if ($price === '') return app('json')->fail('请填写实际支付金额');
  515. if ($price < 0) return app('json')->fail('实际支付金额不能小于0元');
  516. if ($order['pay_price'] == $price) return app('json')->successful('修改成功');
  517. $order['order_id'] = StoreOrder::changeOrderId($order['order_id']);
  518. if (!StoreOrder::edit(['pay_price' => $price, 'order_id' => $order['order_id']], $order['id'], 'id'))
  519. return app('json')->fail('状态错误');
  520. $order['pay_price'] = $price;
  521. event('StoreProductOrderEditAfter', [$order, $order['id']]);
  522. StoreOrderStatus::status($order['id'], 'order_edit', '修改实际支付金额' . $price);
  523. //改价短信提醒
  524. if ($price != $order['pay_price']) {
  525. $switch = sys_config('price_revision_switch') ? true : false;
  526. ShortLetterRepositories::send($switch, $order['user_phone'], ['order_id' => $order_id, 'pay_price' => $order['pay_price']], 'PRICE_REVISION_CODE');
  527. }
  528. return app('json')->successful('修改成功');
  529. }
  530. return app('json')->fail('状态错误');
  531. }
  532. /**
  533. * 订单备注
  534. * @param Request $request
  535. * @return mixed
  536. * @throws DataNotFoundException
  537. * @throws ModelNotFoundException
  538. * @throws DbException
  539. */
  540. public function remark(Request $request)
  541. {
  542. $uid = $request->uid();
  543. // if (!StoreService::orderServiceStatus($uid))
  544. // return app('json')->fail('权限不足');
  545. list($order_id, $remark) = UtilService::postMore([
  546. ['order_id', ''],
  547. ['remark', '']
  548. ], $request, true);
  549. $where = [];
  550. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  551. if ($info) {
  552. $where['store_id'] = $info['store_id'];
  553. }
  554. $order = StoreOrder::getAdminOrderDetail($order_id, 'id', $where);
  555. if (!$order) return app('json')->fail('订单不存在');
  556. $order = $order->toArray();
  557. if (!strlen(trim($remark))) return app('json')->fail('请填写备注内容');
  558. if (!StoreOrder::edit(['remark' => $remark], $order['id']))
  559. return app('json')->fail('备注失败');
  560. return app('json')->successful('备注成功');
  561. }
  562. /**
  563. * 订单交易额/订单数量时间统计
  564. * @param Request $request
  565. * @return bool
  566. */
  567. public function time(Request $request)
  568. {
  569. $uid = $request->uid();
  570. // if (!StoreService::orderServiceStatus($uid))
  571. // return app('json')->fail('权限不足');
  572. list($start, $stop, $type) = UtilService::getMore([
  573. ['start', strtotime(date('Y-m'))],
  574. ['stop', time()],
  575. ['type', 1]
  576. ], $request, true);
  577. $where = [];
  578. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  579. if ($info) {
  580. $where['store_id'] = $info['store_id'];
  581. }
  582. if ($start == $stop) {
  583. return app('json')->fail('开始时间不能等于结束时间');
  584. }
  585. if ($start > $stop) {
  586. $middle = $stop;
  587. $stop = $start;
  588. $start = $middle;
  589. }
  590. $space = bcsub($stop, $start, 0);//间隔时间段
  591. $front = bcsub($start, $space, 0);//第一个时间段
  592. if ($type == 1) {//销售额
  593. $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($front, $start, $where);
  594. $afterPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $stop, $where);
  595. $chartInfo = StoreOrder::chartTimePrice($start, $stop, $where);
  596. $data['chart'] = $chartInfo;//营业额图表数据
  597. $data['time'] = $afterPrice;//时间区间营业额
  598. $increase = (float)bcsub($afterPrice, $frontPrice, 2); //同比上个时间区间增长营业额
  599. $growthRate = abs($increase);
  600. if ($growthRate == 0) $data['growth_rate'] = 0;
  601. else if ($frontPrice == 0) $data['growth_rate'] = $growthRate;
  602. else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontPrice, 2), 100, 0);//时间区间增长率
  603. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  604. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  605. } else {//订单数
  606. $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($front, $start, $where);
  607. $afterNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $stop, $where);
  608. $chartInfo = StoreOrder::chartTimeNumber($start, $stop, $where);
  609. $data['chart'] = $chartInfo;//订单数图表数据
  610. $data['time'] = $afterNumber;//时间区间订单数
  611. $increase = (int)bcsub($afterNumber, $frontNumber, 0); //同比上个时间区间增长订单数
  612. $growthRate = abs($increase);
  613. if ($growthRate == 0) $data['growth_rate'] = 0;
  614. else if ($frontNumber == 0) $data['growth_rate'] = $growthRate;
  615. else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontNumber, 2), 100, 0);//时间区间增长率
  616. $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
  617. $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
  618. }
  619. return app('json')->successful($data);
  620. }
  621. public function month(Request $request)
  622. {
  623. $uid = $request->uid();
  624. $where = [];
  625. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  626. if ($info) {
  627. $where['store_id'] = $info['store_id'];
  628. }
  629. $start = StoreOrder::min('add_time');
  630. $data = [];
  631. while ($start < time()) {
  632. $start_month = date('Y-m', $start);
  633. $end = strtotime('+1month', strtotime($start_month)) - 1;
  634. $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $end, $where);
  635. $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $end, $where);
  636. $start = $end + 1;
  637. $data[$start_month] = compact('frontPrice', 'frontNumber');
  638. }
  639. return app('json')->successful($data);
  640. }
  641. /**
  642. * 订单支付
  643. * @param Request $request
  644. * @return mixed
  645. * @throws DataNotFoundException
  646. * @throws ModelNotFoundException
  647. * @throws DbException
  648. */
  649. public function offline(Request $request)
  650. {
  651. $uid = $request->uid();
  652. list($orderId) = UtilService::postMore([['order_id', '']], $request, true);
  653. $where = [];
  654. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  655. if ($info) {
  656. $where['store_id'] = $info['store_id'];
  657. }
  658. $orderInfo = StoreOrder::getAdminOrderDetail($orderId, 'id', $where);
  659. if (!$orderInfo) return app('json')->fail('参数错误');
  660. $id = $orderInfo->id;
  661. $res = StoreOrder::updateOffline($id);
  662. if ($res) {
  663. event('StoreProductOrderOffline', [$id]);
  664. StoreOrderStatus::status($id, 'offline', '线下付款');
  665. return app('json')->successful('修改成功!');
  666. }
  667. return app('json')->fail(StoreOrder::getErrorInfo('修改失败!'));
  668. }
  669. /**
  670. * 订单退款
  671. * @param Request $request
  672. * @return mixed
  673. * @throws \think\Exception
  674. * @throws DataNotFoundException
  675. * @throws ModelNotFoundException
  676. * @throws DbException
  677. */
  678. public function refund(Request $request)
  679. {
  680. $uid = $request->uid();
  681. list($orderId, $price, $type) = UtilService::postMore([
  682. ['order_id', ''],
  683. ['price', 0],
  684. ['type', 1],
  685. ], $request, true);
  686. $where = [];
  687. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  688. if ($info) {
  689. $where['store_id'] = $info['store_id'];
  690. }
  691. if (!strlen(trim($orderId))) return app('json')->fail('参数错误');
  692. $orderInfo = StoreOrder::getAdminOrderDetail($orderId, '*', $where);
  693. if (!$orderInfo) return app('json')->fail('数据不存在!');
  694. $orderInfo = $orderInfo->toArray();
  695. if ($type == 1)
  696. $data['refund_status'] = 2;
  697. else if ($type == 2)
  698. $data['refund_status'] = 0;
  699. else
  700. return app('json')->fail('退款修改状态错误');
  701. if ($orderInfo['pay_price'] == 0 || $type == 2) {
  702. StoreOrder::update($data, ['order_id' => $orderId]);
  703. return app('json')->successful('修改退款状态成功!');
  704. }
  705. if ($orderInfo['pay_price'] == $orderInfo['refund_price']) return app('json')->fail('已退完支付金额!不能再退款了');
  706. if (!$price) return app('json')->fail('请输入退款金额');
  707. $data['refund_price'] = bcadd($price, $orderInfo['refund_price'], 2);
  708. $bj = bccomp((float)$orderInfo['pay_price'], (float)$data['refund_price'], 2);
  709. if ($bj < 0) return app('json')->fail('退款金额大于支付金额,请修改退款金额');
  710. $refundData['pay_price'] = bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2);
  711. $refundData['refund_price'] = $price;
  712. $refundData['refund_id'] = $orderInfo['order_id'] . time();
  713. if ($orderInfo['pay_type'] == 'weixin') {
  714. if ($orderInfo['is_channel'] == 1) {// 小程序
  715. try {
  716. MiniProgramService::payOrderRefund($orderInfo['order_id'], $refundData);
  717. } catch (\Exception $e) {
  718. return app('json')->fail($e->getMessage());
  719. }
  720. } else {// 公众号
  721. try {
  722. WechatService::payOrderRefund($orderInfo['order_id'], $refundData);
  723. } catch (\Exception $e) {
  724. return app('json')->fail($e->getMessage());
  725. }
  726. }
  727. } else if ($orderInfo['pay_type'] == 'yue') {//余额
  728. StoreOrder::beginTrans();
  729. $userInfo = User::getUserInfo($orderInfo['uid'], 'now_money');
  730. if (!$userInfo) {
  731. StoreOrder::rollbackTrans();
  732. return app('json')->fail('订单用户不存在');
  733. }
  734. $res1 = User::bcInc($orderInfo['uid'], 'now_money', $price, 'uid');
  735. $res2 = $res2 = UserBill::income('商品退款', $orderInfo['uid'], 'now_money', 'pay_product_refund', $price, $orderInfo['id'], bcadd($userInfo['now_money'], $price, 2), '订单退款到余额' . floatval($price) . '元');
  736. try {
  737. OrderRepository::storeOrderYueRefund($orderInfo, $refundData);
  738. } catch (\Exception $e) {
  739. StoreOrder::rollbackTrans();
  740. return app('json')->fail($e->getMessage());
  741. }
  742. $res = $res1 && $res2;
  743. StoreOrder::checkTrans($res);
  744. if (!$res) return app('json')->fail('余额退款失败!');
  745. }
  746. $resEdit = StoreOrder::edit($data, $orderInfo['id'], 'id');
  747. if ($resEdit) {
  748. $data['type'] = $type;
  749. if ($data['type'] == 1) StorePink::setRefundPink($orderInfo['id']);
  750. try {
  751. OrderRepository::storeProductOrderRefundY($data, $orderInfo['id']);
  752. } catch (\Exception $e) {
  753. return app('json')->fail($e->getMessage());
  754. }
  755. StoreOrderStatus::status($orderInfo['id'], 'refund_price', '退款给用户' . $price . '元');
  756. SystemStoreBill::where('category', 'brokerage_price')
  757. //->where('type', 'brokerage')
  758. ->where('link_id', $orderId)
  759. ->where('pm', 1)
  760. ->where('status', 0)
  761. ->update(['status' => -1]);
  762. \app\admin\model\user\UserBill::where('category', 'now_money')
  763. ->where('type', 'brokerage')
  764. ->where('link_id', $orderId)
  765. ->where('pm', 1)
  766. ->where('status', 0)
  767. ->update(['status' => -1]);
  768. //退佣金
  769. $brokerage_list = UserBill::where('category', 'now_money')
  770. ->where('type', 'brokerage')
  771. ->where('link_id', $orderId)
  772. ->where('pm', 1)
  773. ->where('status', 1)
  774. ->select()->toArray();
  775. if ($brokerage_list)
  776. foreach ($brokerage_list as $item) {
  777. $usermoney = User::where('uid', $item['uid'])->value('brokerage_price');
  778. if ($item['number'] > $usermoney)
  779. $item['number'] = $usermoney;
  780. User::bcDec($item['uid'], 'brokerage_price', $item['number'], 'uid');
  781. UserBill::expend('退款退佣金', $item['uid'], 'now_money', 'brokerage', $item['number'], $orderId, bcsub($usermoney, $item['number'], 2), '订单退款扣除佣金' . floatval($item['number']) . '元');
  782. }
  783. return app('json')->successful('修改成功!');
  784. } else {
  785. StoreOrderStatus::status($orderInfo['id'], 'refund_price', '退款给用户' . $price . '元失败');
  786. return app('json')->successful('修改失败!');
  787. }
  788. }
  789. /**
  790. * 门店核销
  791. * @param Request $request
  792. * @return
  793. * @throws DataNotFoundException
  794. * @throws DbException
  795. * @throws ModelNotFoundException
  796. */
  797. public function order_verific(Request $request)
  798. {
  799. $uid = $request->uid();
  800. list($verify_code, $is_confirm) = UtilService::postMore([
  801. ['verify_code', ''],
  802. ['is_confirm', 0]
  803. ], $request, true);
  804. if (!$verify_code) return app('json')->fail('缺少核销码');
  805. $orderInfo = StoreOrder::where('verify_code', $verify_code)->where('store_id', 'in', [SystemStoreStaff::where('uid', $uid)->value('store_id'), 0])->where('paid', 1)->where('refund_status', 0)->find();
  806. if (!$orderInfo) return app('json')->fail('核销的订单不存在于该门店或未支付或已退款');
  807. if ($orderInfo->status > 0) return app('json')->fail('订单已经核销');
  808. if ($orderInfo->combination_id && $orderInfo->pink_id) {
  809. $res = StorePink::where('id', $orderInfo->pink_id)->where('status', '<>', 2)->count();
  810. if ($res) return app('json')->fail('拼团订单暂未成功无法核销!');
  811. }
  812. if (!$is_confirm) {
  813. $orderInfo['image'] = StoreCart::getProductImage($orderInfo->cart_id);
  814. return app('json')->success($orderInfo->toArray());
  815. }
  816. StoreOrder::beginTrans();
  817. try {
  818. if (SystemStoreStaff::verifyStatus($uid) && ($storeStaff = SystemStoreStaff::where('uid', $uid)->field(['store_id', 'id'])->find())) {
  819. // $orderInfo->store_id = $storeStaff['store_id'];
  820. $orderInfo->clerk_id = $storeStaff['id'];
  821. }
  822. $orderInfo->status = 2;
  823. $orderInfo->verify_time = time();
  824. if ($orderInfo->store_id == 0) {
  825. $orderInfo->store_id = SystemStoreStaff::where('uid', $uid)->value('store_id');
  826. $store = SystemStore::get($orderInfo->store_id);
  827. $orderInfo->province = explode(',', $store['address'])[0] ?? '';
  828. $orderInfo->city = explode(',', $store['address'])[1] ?? '';
  829. $orderInfo->district = explode(',', $store['address'])[2] ?? '';
  830. SystemStore::decStock($orderInfo);
  831. }
  832. if ($orderInfo->save()) {
  833. OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo);
  834. StoreOrderStatus::status($orderInfo->id, 'take_delivery', '已核销');
  835. event('ShortMssageSend', [$orderInfo['order_id'], 'Receiving']);
  836. StoreOrder::commitTrans();
  837. return app('json')->success('核销成功');
  838. } else {
  839. StoreOrder::rollbackTrans();
  840. return app('json')->fail('核销失败');
  841. }
  842. } catch (\PDOException $e) {
  843. StoreOrder::rollbackTrans();
  844. return app('json')->fail($e->getMessage());
  845. } catch (\Exception $e) {
  846. StoreOrder::rollbackTrans();
  847. return app('json')->fail($e->getMessage());
  848. }
  849. }
  850. /**
  851. * 门店核销
  852. * @param Request $request
  853. * @return
  854. * @throws DataNotFoundException
  855. * @throws DbException
  856. * @throws ModelNotFoundException
  857. */
  858. public function exchange_order_verific(Request $request)
  859. {
  860. $uid = $request->uid();
  861. list($verify_code, $is_confirm) = UtilService::postMore([
  862. ['verify_code', ''],
  863. ['is_confirm', 0]
  864. ], $request, true);
  865. if (!$verify_code) return app('json')->fail('缺少核销码');
  866. $orderInfo = StoreExchangeOrder::where('verify_code', $verify_code)->where('store_id', 'in', [SystemStoreStaff::where('uid', $uid)->value('store_id'), 0])->where('refund_status', 0)->find();
  867. if (!$orderInfo) return app('json')->fail('核销的兑换券不存在于该门店或未支付或已退款');
  868. if ($orderInfo->status == 2) return app('json')->fail('兑换券已经失效');
  869. if ($orderInfo->status > 0) return app('json')->fail('兑换券已经核销');
  870. if (!$is_confirm) {
  871. $orderInfo['image'] = StoreCart::getProductImage($orderInfo->cart_id);
  872. return app('json')->success($orderInfo->toArray());
  873. }
  874. StoreExchangeOrder::beginTrans();
  875. try {
  876. if (SystemStoreStaff::verifyStatus($uid) && ($storeStaff = SystemStoreStaff::where('uid', $uid)->field(['store_id', 'id'])->find())) {
  877. $orderInfo->clerk_id = $storeStaff['id'];
  878. }
  879. $orderInfo->status = 1;
  880. $orderInfo->verify_time = time();
  881. if ($orderInfo->store_id == 0) {
  882. $orderInfo->store_id = SystemStoreStaff::where('uid', $uid)->value('store_id');
  883. SystemStore::decStock($orderInfo);
  884. }
  885. if ($orderInfo->save()) {
  886. StoreExchangeOrder::commitTrans();
  887. return app('json')->success('核销成功');
  888. } else {
  889. StoreExchangeOrder::rollbackTrans();
  890. return app('json')->fail('核销失败');
  891. }
  892. } catch (\PDOException $e) {
  893. StoreExchangeOrder::rollbackTrans();
  894. return app('json')->fail($e->getMessage());
  895. } catch (\Exception $e) {
  896. StoreExchangeOrder::rollbackTrans();
  897. return app('json')->fail($e->getMessage());
  898. }
  899. }
  900. public function rechargeList(Request $request)
  901. {
  902. $uid = $request->uid();
  903. $where = UtilService::getMore([
  904. ['page', 1],
  905. ['limit', 20],
  906. ]);
  907. $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
  908. if (!$info) {
  909. return app('json')->fail('权限不足');
  910. }
  911. $where['store_id'] = $info['store_id'];
  912. return app('json')->successful('ok', UserRecharge::getStoreRechargeList($where));
  913. }
  914. public function back_deposit(Request $request)
  915. {
  916. $uid = $request->uid();
  917. $data = UtilService::postMore([
  918. ['order_id', ''],
  919. ['refund_price', 0],
  920. ['type', 1],
  921. ]);
  922. if (!$data['order_id']) return app('json')->fail('数据不存在');
  923. $orderInfo = StoreOrder::where('order_id', $data['order_id'])->where('store_id', SystemStoreStaff::where('uid', $uid)->value('store_id'))->find();
  924. if (!$orderInfo) return app('json')->fail('订单不存在于该门店');
  925. if ($orderInfo['deposit'] == $orderInfo['deposit_back']) return app('json')->fail('已退完押金!不能再退款了');
  926. if (!$data['refund_price']) return app('json')->fail('请输入退款金额');
  927. $refund_price = $data['refund_price'];
  928. $data['deposit_back'] = bcadd($data['refund_price'], $orderInfo['deposit_back'], 2);
  929. $bj = bccomp((float)$orderInfo['deposit'], (float)$data['deposit_back'], 2);
  930. if ($bj < 0) return app('json')->fail('退押金额大于支付押金,请修改退押金额');
  931. if ($data['type'] == 1) {
  932. $data['deposit_status'] = 1;
  933. } else if ($data['type'] == 2) {
  934. $data['deposit_status'] = 0;
  935. }
  936. // $type = $data['type'];
  937. unset($data['type']);
  938. unset($data['refund_price']);
  939. $refund_data['pay_price'] = bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2);
  940. $refund_data['refund_price'] = $refund_price;
  941. $refund_data['refund_id'] = 'refund_deposit' . $orderInfo['order_id'] . time();
  942. if ($orderInfo['pay_type'] == 'weixin') {
  943. if ($orderInfo['is_channel'] == 1) {//小程序
  944. try {
  945. MiniProgramService::payOrderRefund($orderInfo['order_id'], $refund_data);//2.5.36
  946. } catch (\Exception $e) {
  947. return app('json')->fail($e->getMessage());
  948. }
  949. } else {//TODO 公众号
  950. try {
  951. WechatService::payOrderRefund($orderInfo['order_id'], $refund_data);
  952. } catch (\Exception $e) {
  953. return app('json')->fail($e->getMessage());
  954. }
  955. }
  956. } else if ($orderInfo['pay_type'] == 'yue') {
  957. BaseModel::beginTrans();
  958. $usermoney = User::where('uid', $orderInfo['uid'])->value('now_money');
  959. $res1 = User::bcInc($orderInfo['uid'], 'now_money', $refund_price, 'uid');
  960. $res2 = UserBill::income('商品退押金', $orderInfo['uid'], 'now_money', 'pay_deposit_refund', $refund_price, $orderInfo['id'], bcadd($usermoney, $refund_price, 2), '订单退押金到余额' . floatval($refund_price) . '元');
  961. $res = $res1 && $res2;
  962. BaseModel::checkTrans($res);
  963. if (!$res) return app('json')->fail('余额退押金失败!');
  964. }
  965. $resEdit = StoreOrder::edit($data, $orderInfo['id']);
  966. if ($resEdit) {
  967. \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['id'], 'refund_deposit', '退押金给用户' . $refund_price . '元');
  968. return app('json')->success('成功!');
  969. } else {
  970. \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['id'], 'refund_deposit', '退押金给用户' . $refund_price . '元失败');
  971. return app('json')->fail('失败!');
  972. }
  973. }
  974. public function exchange_order_back_deposit(Request $request)
  975. {
  976. $uid = $request->uid();
  977. $data = UtilService::postMore([
  978. ['id', ''],
  979. ['refund_price', 0],
  980. ['type', 1],
  981. ], $request);
  982. // var_dump($data);
  983. if (!$data['id']) return app('json')->fail('数据不存在');
  984. $orderInfo = StoreExchangeOrder::where('id', $data['id'])->where('store_id', SystemStoreStaff::where('uid', $uid)->value('store_id'))->where('refund_status', 0)->find();
  985. if (!$orderInfo) return app('json')->fail('订单不存在于该门店或未支付或已退款');
  986. if ($orderInfo['deposit'] == $orderInfo['deposit_back']) return app('json')->fail('已退完押金!不能再退款了');
  987. if (!$data['refund_price']) return app('json')->fail('请输入退款金额');
  988. $refund_price = $data['refund_price'];
  989. $data['deposit_back'] = bcadd($data['refund_price'], $orderInfo['deposit_back'], 2);
  990. $bj = bccomp((float)$orderInfo['deposit'], (float)$data['deposit_back'], 2);
  991. if ($bj < 0) return app('json')->fail('退押金额大于支付押金,请修改退押金额');
  992. if ($data['type'] == 1) {
  993. $data['deposit_status'] = 1;
  994. } else if ($data['type'] == 2) {
  995. $data['deposit_status'] = 0;
  996. }
  997. // $type = $data['type'];
  998. unset($data['type']);
  999. unset($data['refund_price']);
  1000. $refund_data['pay_price'] = bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2);
  1001. $refund_data['refund_price'] = $refund_price;
  1002. $refund_data['refund_id'] = 'refund_deposit' . $orderInfo['order_id'] . time();
  1003. $order = StoreOrderModel::where('order_id', $orderInfo['order_id'])->find();
  1004. if ($order['pay_type'] == 'weixin') {
  1005. if ($order['is_channel'] == 1) {//小程序
  1006. try {
  1007. MiniProgramService::payOrderRefund($orderInfo['order_id'], $refund_data);//2.5.36
  1008. } catch (\Exception $e) {
  1009. return app('json')->fail($e->getMessage());
  1010. }
  1011. } else {//TODO 公众号
  1012. try {
  1013. WechatService::payOrderRefund($orderInfo['order_id'], $refund_data);
  1014. } catch (\Exception $e) {
  1015. return app('json')->fail($e->getMessage());
  1016. }
  1017. }
  1018. } else if ($orderInfo['pay_type'] == 'yue') {
  1019. BaseModel::beginTrans();
  1020. $usermoney = User::where('uid', $orderInfo['uid'])->value('now_money');
  1021. $res1 = User::bcInc($orderInfo['uid'], 'now_money', $refund_price, 'uid');
  1022. $res2 = UserBill::income('商品退押金', $orderInfo['uid'], 'now_money', 'pay_deposit_refund', $refund_price, $orderInfo['id'], bcadd($usermoney, $refund_price, 2), '订单退押金到余额' . floatval($refund_price) . '元');
  1023. $res = $res1 && $res2;
  1024. BaseModel::checkTrans($res);
  1025. if (!$res) return app('json')->fail('余额退押金失败!');
  1026. }
  1027. $resEdit = StoreExchangeOrder::edit($data, $orderInfo['id']);
  1028. if ($resEdit) {
  1029. \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['oid'], 'refund_deposit', '退押金给用户' . $refund_price . '元');
  1030. return app('json')->success('成功!');
  1031. } else {
  1032. \app\admin\model\order\StoreOrderStatus::setStatus($orderInfo['oid'], 'refund_deposit', '退押金给用户' . $refund_price . '元失败');
  1033. return app('json')->fail('失败!');
  1034. }
  1035. }
  1036. }