StoreOrderController.php 45 KB

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