StoreOrderController.php 45 KB

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