SystemStore.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <?php
  2. namespace app\admin\controller\merchant;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\order\StoreOrder as StoreOrderModel;
  5. use app\admin\model\order\StoreOrderStatus;
  6. use app\admin\model\store\StoreProductAttr;
  7. use app\admin\model\store\StoreProductAttrValue;
  8. use app\admin\model\system\ShippingTemplates;
  9. use app\admin\model\system\SystemStoreBill;
  10. use app\admin\model\system\SystemStoreExtract;
  11. use app\admin\model\system\SystemStorePoint;
  12. use app\admin\model\system\SystemStoreProductStock;
  13. use app\admin\model\system\SystemStoreSender;
  14. use app\admin\model\ump\StorePink;
  15. use app\admin\model\user\User;
  16. use app\models\store\StoreCart;
  17. use app\models\store\StoreOrder;
  18. use crmeb\repositories\OrderRepository;
  19. use crmeb\services\FormBuilder;
  20. use crmeb\services\JsonService;
  21. use app\admin\model\system\SystemStore as SystemStoreModel;
  22. use crmeb\services\UtilService;
  23. use Exception;
  24. use think\db\exception\DataNotFoundException;
  25. use think\db\exception\DbException;
  26. use think\db\exception\ModelNotFoundException;
  27. use think\facade\Route;
  28. use think\facade\Session;
  29. /**
  30. * 门店后台控制器
  31. * Class SystemAttachment
  32. * @package app\admin\controller\system
  33. *
  34. */
  35. class SystemStore extends AuthController
  36. {
  37. private $store_id;
  38. public function initialize()
  39. {
  40. parent::initialize(); // TODO: Change the autogenerated stub
  41. $this->store_id = Session::get('store_id', 0);
  42. if ($this->storeId) $this->store_id = $this->storeId;
  43. }
  44. /**
  45. * 门店列表
  46. * @throws Exception
  47. */
  48. public function list()
  49. {
  50. $where = UtilService::getMore([
  51. ['page', 1],
  52. ['limit', 20],
  53. ['name', ''],
  54. ['level', ''],
  55. ['excel', 0],
  56. ['parent_id', $this->request->param('pid', '')],
  57. ['type', $this->request->param('type')]
  58. ]);
  59. JsonService::successlayui(SystemStoreModel::getStoreList($where));
  60. }
  61. /**
  62. * 选择门店
  63. * @param string $origin
  64. * @return string
  65. * @throws Exception
  66. */
  67. public function index($origin = '')
  68. {
  69. // var_dump($origin);
  70. // Session::delete('store_id');
  71. if ($this->storeId) {
  72. $this->redirect($origin ?: 'order');
  73. }
  74. if ($this->request->get('store_id', 0)) {
  75. Session::set('store_id', $this->request->get('store_id', 0));
  76. $this->redirect($origin ?: 'index');
  77. }
  78. $type = $this->request->param('type');
  79. $show = SystemStoreModel::where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
  80. $hide = SystemStoreModel::where('is_show', 0)->count();//隐藏的门店
  81. $recycle = SystemStoreModel::where('is_del', 1)->count();//删除的门店
  82. if ($type == null) $type = 1;
  83. // $this->assign('pid', $this->request->get('pid', 0));
  84. $this->assign(compact('type', 'show', 'hide', 'recycle'));
  85. $this->assign('origin', url($origin ?: 'index'));
  86. // $this->assign('level_list', $new);
  87. return $this->fetch();
  88. }
  89. /**
  90. * @return string
  91. * @throws Exception
  92. */
  93. public function order()
  94. {
  95. // var_dump($this->storeId);
  96. if (!$this->store_id) {
  97. $this->redirect(url('index', array('origin' => 'order'))->build());
  98. }
  99. $this->assign([
  100. 'year' => get_month(),
  101. 'store_name' => SystemStoreModel::get($this->store_id)['name'],
  102. 'real_name' => $this->request->get('real_name', ''),
  103. 'status' => $this->request->param('status', ''),
  104. 'orderCount' => StoreOrderModel::orderCount($this->store_id),
  105. 'payTypeCount' => StoreOrderModel::payTypeCount($this->store_id),
  106. ]);
  107. $this->assign('store_id', $this->store_id);
  108. return $this->fetch();
  109. }
  110. public function add_order()
  111. {
  112. if (!$this->store_id) {
  113. $this->failed('未知门店');
  114. }
  115. // $store_info = SystemStoreModel::get($this->store_id);
  116. $stocks = SystemStoreProductStock::getStockList(['excel' => 0, 'page' => 1, 'limit' => PHP_INT_MAX], $this->store_id)['data'];
  117. if ($stocks) $stocks = $stocks->toArray();
  118. // dump($stocks);
  119. $products = function () use ($stocks) {
  120. $return = [];
  121. foreach ($stocks as $v) {
  122. $return[] = ['label' => $v['product_info']['store_name'] . "|" . $v['product_info']['product_attr_info']['suk'] . "【库存:{$v['stock']}】", 'value' => $v['unique']];
  123. }
  124. return $return;
  125. };
  126. $f = array();
  127. $f[] = FormBuilder::select('uni', '商品')->setOptions($products())->filterable(true)->required();
  128. $f[] = FormBuilder::number('num', '数量')->step(1)->min(0)->required();
  129. $f[] = FormBuilder::input('real_name', '购买人')->required();
  130. $f[] = FormBuilder::input('phone', '手机号码')->required();
  131. $form = FormBuilder::make_post_form('创建订单', $f, Route::buildUrl('order_save'));
  132. $this->assign(compact('form'));
  133. return $this->fetch('public/form-builder');
  134. }
  135. public function order_save()
  136. {
  137. if (!$this->store_id) {
  138. JsonService::fail('未知门店');
  139. }
  140. $date = UtilService::postMore([
  141. ['uni', ''],
  142. ['num', 0],
  143. ['real_name', ''],
  144. ['phone', ''],
  145. ], $this->request);
  146. if (!$date['uni']) JsonService::fail('请选择规格');
  147. if (!$date['num']) JsonService::fail('请输入购买数量');
  148. $uid = User::where('admin_id', $this->adminId)->value('uid');
  149. if (!$uid) JsonService::fail('请先绑定前台账户');
  150. $product = StoreProductAttrValue::where('unique', $date['uni'])->find();
  151. if (!$product) JsonService::fail('规格不存在');
  152. $res = StoreCart::setCart($uid, $product['product_id'], $date['num'], $date['uni'], 'product', 1);
  153. if ($res) {
  154. $cartId = $res->id;
  155. $cartGroup = StoreCart::getUserProductCartList($uid, [$cartId], 1, $this->store_id);
  156. if (count($cartGroup['invalid'])) JsonService::fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
  157. if (!$cartGroup['valid']) JsonService::fail('请提交购买的商品');
  158. $cartInfo = $cartGroup['valid'];
  159. $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, 0);
  160. $other = [
  161. 'offlinePostage' => sys_config('offline_postage'),
  162. 'integralRatio' => sys_config('integral_ratio'),
  163. 'store_id' => $this->store_id,
  164. ];
  165. $orderKey = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
  166. if (!$orderKey) JsonService::fail('生成订单错误!');
  167. if (StoreOrder::be(['order_id|unique' => $orderKey, 'uid' => $uid, 'is_del' => 0]))
  168. JsonService::fail('订单已生成');
  169. $order = StoreOrder::cacheKeyCreateOrder($uid, $orderKey, 0, 'offline', false, 0, '加盟店后台订单', 0, 0, 0, 0, 0, 0, false, 1, 2, $date['real_name'], $date['phone'], $this->store_id, 0, 1);
  170. if ($order === false) JsonService::fail(StoreOrder::getErrorInfo('订单生成失败'));
  171. else JsonService::success('订单已生成');
  172. } else {
  173. JsonService::fail('加入购物车失败');
  174. }
  175. }
  176. /**
  177. * 核销码核销
  178. * @param string $verify_code
  179. * @param int $is_confirm
  180. * @return string
  181. * @throws DataNotFoundException
  182. * @throws DbException
  183. * @throws ModelNotFoundException
  184. * @throws Exception
  185. */
  186. public function write_order($verify_code = '', $is_confirm = 0)
  187. {
  188. if ($this->request->isAjax()) {
  189. if (!$this->store_id) {
  190. JsonService::fail('未知门店');
  191. }
  192. if (!$verify_code) JsonService::fail('缺少核销码!');
  193. StoreOrderModel::beginTrans();
  194. $orderInfo = StoreOrderModel::where('store_id', $this->store_id)->where('verify_code', $verify_code)->where('paid', 1)->where('refund_status', 0)->find();
  195. if (!$orderInfo) JsonService::fail('核销订单不存在!');
  196. if ($orderInfo->status > 0) JsonService::fail('订单已核销!');
  197. if ($orderInfo->combination_id && $orderInfo->pink_id) {
  198. $res = StorePink::where('id', $orderInfo->pink_id)->where('status', '<>', 2)->count();
  199. if ($res) JsonService::fail('拼团订单暂未成功无法核销!');
  200. }
  201. if ($is_confirm == 0) {
  202. $orderInfo['nickname'] = User::where(['uid' => $orderInfo['uid']])->value('nickname');
  203. JsonService::successful($orderInfo);
  204. }
  205. $orderInfo->status = 2;
  206. if ($orderInfo->save()) {
  207. OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo);
  208. StoreOrderStatus::setStatus($orderInfo->id, 'take_delivery', '已核销');
  209. //发送短信
  210. event('ShortMssageSend', [$orderInfo['order_id'], 'Receiving']);
  211. StoreOrderModel::commitTrans();
  212. JsonService::successful('核销成功!');
  213. } else {
  214. StoreOrderModel::rollbackTrans();
  215. JsonService::fail('核销失败');
  216. }
  217. } else {
  218. if (!$this->store_id) {
  219. $this->redirect(url('index', array('origin' => 'order'))->build());
  220. }
  221. $this->assign('is_layui', 1);
  222. return $this->fetch();
  223. }
  224. }
  225. /**
  226. * 获取订单列表
  227. * return json
  228. */
  229. public function order_list()
  230. {
  231. if (!$this->store_id) {
  232. JsonService::fail('未知门店');
  233. }
  234. $where = UtilService::getMore([
  235. ['status', ''],
  236. ['real_name', $this->request->param('real_name', '')],
  237. ['is_del', 0],
  238. ['data', ''],
  239. ['type', ''],
  240. ['pay_type', ''],
  241. ['order', ''],
  242. ['page', 1],
  243. ['limit', 20],
  244. ['excel', 0]
  245. ]);
  246. $where['store_id'] = $this->store_id;
  247. JsonService::successlayui(StoreOrderModel::OrderList($where));
  248. }
  249. /**
  250. *
  251. */
  252. public function getOrderBadge()
  253. {
  254. if (!$this->store_id) {
  255. JsonService::fail('未知门店');
  256. }
  257. $where = UtilService::postMore([
  258. ['status', ''],
  259. ['real_name', ''],
  260. ['is_del', 0],
  261. ['data', ''],
  262. ['type', ''],
  263. ['pay_type', ''],
  264. ['order', '']
  265. ]);
  266. $where['store_id'] = $this->store_id;
  267. JsonService::successful(StoreOrderModel::getBadge($where));
  268. }
  269. /**
  270. * @return string
  271. * @throws Exception
  272. */
  273. public function bill()
  274. {
  275. if (!$this->store_id) {
  276. $this->redirect(url('index', array('origin' => 'bill'))->build());
  277. }
  278. $this->assign('store_info', SystemStoreModel::get($this->store_id));
  279. $this->assign('id', $this->store_id);
  280. return $this->fetch();
  281. }
  282. public function store_bill_log_list($id)
  283. {
  284. $where = UtilService::getMore([
  285. ['page', 1],
  286. ['limit', 20],
  287. ]);
  288. JsonService::successlayui(SystemStoreBill::getList($where, $id));
  289. }
  290. /**
  291. * @return string
  292. * @throws Exception
  293. */
  294. public function cash()
  295. {
  296. if (!$this->store_id) {
  297. $this->redirect(url('index', array('origin' => 'cash'))->build());
  298. }
  299. $store_info = SystemStoreModel::get($this->store_id);
  300. $f = array();
  301. $f[] = FormBuilder::radio('extract_type', '提现方式', 'bank')->setOptions([['label' => '银行', 'value' => 'bank'],
  302. // ['label' => '支付宝', 'value' => 'alipay'], ['label' => '微信', 'value' => 'weixin']
  303. ]);
  304. $f[] = FormBuilder::number('money', '提现金额', 0)->col(24)->step(0.01)->min(0)->max($store_info['brokerage_price']);
  305. $f[] = FormBuilder::input('name', '姓名', $store_info['leader']);
  306. $f[] = FormBuilder::input('bankname', '开户银行', $store_info['bank_name']);
  307. $f[] = FormBuilder::input('cardnum', '银行卡号', $store_info['bank_card']);
  308. // $f[] = FormBuilder::input('alipay_code', '支付宝账号');
  309. // $f[] = FormBuilder::input('weixin', '微信号');
  310. $form = FormBuilder::make_post_form('发起提现', $f, Route::buildUrl('cash_save'));
  311. $this->assign(compact('form'));
  312. return $this->fetch('public/form-builder');
  313. }
  314. /**
  315. * 提现申请
  316. */
  317. public function cash_save()
  318. {
  319. if (!$this->store_id) {
  320. JsonService::fail('店铺异常');
  321. }
  322. $extractInfo = UtilService::postMore([
  323. ['alipay_code', ''],
  324. ['extract_type', ''],
  325. ['money', 0],
  326. ['name', ''],
  327. ['bankname', ''],
  328. ['cardnum', ''],
  329. ['weixin', ''],
  330. ], $this->request);
  331. if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) JsonService::fail('提现金额输入有误');
  332. $store = SystemStoreModel::get($this->store_id);
  333. if ($extractInfo['money'] > $store['brokerage_price']) JsonService::fail('可提现佣金不足');
  334. if (!$extractInfo['cardnum'] == '')
  335. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  336. JsonService::fail('银行卡号输入有误');
  337. if (SystemStoreExtract::userExtract($store, $extractInfo))
  338. JsonService::successful('申请提现成功!');
  339. else
  340. JsonService::fail(SystemStoreExtract::getErrorInfo('提现失败'));
  341. }
  342. /**
  343. * @return string
  344. * @throws Exception
  345. */
  346. public function info()
  347. {
  348. if (!$this->store_id) {
  349. $this->redirect(url('index', array('origin' => 'info'))->build());
  350. }
  351. $this->assign('store_info', SystemStoreModel::getStoreInfo($this->store_id) ?: []);
  352. return $this->fetch();
  353. }
  354. //TODO 自提点管理
  355. /**
  356. * @return string
  357. * @throws Exception
  358. */
  359. public function point()
  360. {
  361. if (!$this->store_id) {
  362. $this->redirect(url('index', array('origin' => 'point'))->build());
  363. }
  364. $type = $this->request->param('type');
  365. $show = SystemStorePoint::where('store_id', $this->store_id)->where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
  366. $hide = SystemStorePoint::where('store_id', $this->store_id)->where('is_show', 0)->count();//隐藏的门店
  367. $recycle = SystemStorePoint::where('store_id', $this->store_id)->where('is_del', 1)->count();//删除的门店
  368. if ($type == null) $type = 1;
  369. $id = $this->store_id;
  370. $this->assign(compact('type', 'show', 'hide', 'recycle', 'id'));
  371. return $this->fetch();
  372. }
  373. public function store_point_list($id)
  374. {
  375. $where = UtilService::getMore([
  376. ['page', 1],
  377. ['limit', 20],
  378. ['name', ''],
  379. ['excel', 0],
  380. ['type', $this->request->param('type')]
  381. ]);
  382. $where['store_id'] = $id;
  383. JsonService::successlayui(SystemStorePoint::getStoreList($where));
  384. }
  385. public function add_point($id = 0, $store_id = 0)
  386. {
  387. $store = SystemStorePoint::getStoreDispose($id);
  388. $this->assign(compact('store', 'store_id'));
  389. return $this->fetch();
  390. }
  391. /**
  392. * 保存修改门店信息
  393. * @param int $id
  394. */
  395. public function save_point($id = 0)
  396. {
  397. $data = UtilService::postMore([
  398. ['name', ''],
  399. ['phone', ''],
  400. ['address', ''],
  401. ['detailed_address', ''],
  402. ['latlng', ''],
  403. ['valid_time', []],
  404. ['day_time', []],
  405. ['store_id', 0],
  406. ]);
  407. // var_dump($data['store_id']);
  408. if (!$data['store_id'] || !SystemStoreModel::getStoreDispose($data['store_id'])) JsonService::fail('无效门店');
  409. SystemStorePoint::beginTrans();
  410. try {
  411. $data['address'] = implode(',', $data['address']);
  412. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  413. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) JsonService::fail('请选择门店位置');
  414. $data['latitude'] = $data['latlng'][0];
  415. $data['longitude'] = $data['latlng'][1];
  416. $data['valid_time'] = implode(' - ', $data['valid_time']);
  417. $data['day_time'] = implode(' - ', $data['day_time']);
  418. unset($data['latlng']);
  419. if ($id) {
  420. if (SystemStorePoint::where('id', $id)->update($data)) {
  421. SystemStorePoint::commitTrans();
  422. JsonService::success('修改成功');
  423. } else {
  424. SystemStorePoint::rollbackTrans();
  425. JsonService::fail('修改失败或者您没有修改什么!');
  426. }
  427. } else {
  428. $data['add_time'] = time();
  429. $data['is_show'] = 1;
  430. if ($res = SystemStorePoint::create($data)) {
  431. SystemStorePoint::commitTrans();
  432. JsonService::success('保存成功', ['id' => $res->id]);
  433. } else {
  434. SystemStorePoint::rollbackTrans();
  435. JsonService::fail('保存失败!');
  436. }
  437. }
  438. } catch (\Exception $e) {
  439. SystemStorePoint::rollbackTrans();
  440. JsonService::fail($e->getMessage());
  441. }
  442. }
  443. /**
  444. * 设置单个门店是否显示
  445. * @param string $is_show
  446. * @param string $id
  447. * @return json
  448. */
  449. public function set_point_show($is_show = '', $id = '')
  450. {
  451. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  452. $res = SystemStorePoint::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  453. if ($res) {
  454. return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
  455. } else {
  456. return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
  457. }
  458. }
  459. /**
  460. * 删除恢复门店
  461. * @param $id
  462. */
  463. public function point_delete($id)
  464. {
  465. if (!$id) return $this->failed('数据不存在');
  466. if (!SystemStorePoint::be(['id' => $id])) return $this->failed('数据不存在');
  467. if (SystemStorePoint::be(['id' => $id, 'is_del' => 1])) {
  468. $data['is_del'] = 0;
  469. if (!SystemStorePoint::edit($data, $id))
  470. return JsonService::fail(SystemStorePoint::getErrorInfo('恢复失败,请稍候再试!'));
  471. else
  472. return JsonService::successful('恢复门店成功!');
  473. } else {
  474. $data['is_del'] = 1;
  475. if (!SystemStorePoint::edit($data, $id))
  476. return JsonService::fail(SystemStorePoint::getErrorInfo('删除失败,请稍候再试!'));
  477. else
  478. return JsonService::successful('删除门店成功!');
  479. }
  480. }
  481. //TODO 自提点管理
  482. /**
  483. * @return string
  484. * @throws Exception
  485. */
  486. public function sender()
  487. {
  488. if (!$this->store_id) {
  489. $this->redirect(url('index', array('origin' => 'sender'))->build());
  490. }
  491. $type = $this->request->param('type');
  492. $show = SystemStoreSender::where('store_id', $this->store_id)->where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
  493. $hide = SystemStoreSender::where('store_id', $this->store_id)->where('is_show', 0)->count();//隐藏的门店
  494. $recycle = SystemStoreSender::where('store_id', $this->store_id)->where('is_del', 1)->count();//删除的门店
  495. if ($type == null) $type = 1;
  496. $id = $this->store_id;
  497. $this->assign(compact('type', 'show', 'hide', 'recycle', 'id'));
  498. return $this->fetch();
  499. }
  500. public function store_sender_list($id)
  501. {
  502. $where = UtilService::getMore([
  503. ['page', 1],
  504. ['limit', 20],
  505. ['name', ''],
  506. ['excel', 0],
  507. ['type', $this->request->param('type')]
  508. ]);
  509. $where['store_id'] = $id;
  510. JsonService::successlayui(SystemStoreSender::getStoreList($where));
  511. }
  512. public function add_sender($id = 0, $store_id = 0)
  513. {
  514. $store = SystemStoreSender::getStoreDispose($id);
  515. $this->assign(compact('store', 'store_id'));
  516. return $this->fetch();
  517. }
  518. /**
  519. * 保存修改门店信息
  520. * @param int $id
  521. */
  522. public function save_sender($id = 0)
  523. {
  524. $data = UtilService::postMore([
  525. ['name', ''],
  526. ['phone', ''],
  527. ['store_id', 0],
  528. ]);
  529. // var_dump($data['store_id']);
  530. if (!$data['store_id'] || !SystemStoreModel::getStoreDispose($data['store_id'])) JsonService::fail('无效门店');
  531. SystemStoreSender::beginTrans();
  532. try {
  533. if ($id) {
  534. if (SystemStoreSender::where('id', $id)->update($data)) {
  535. SystemStoreSender::commitTrans();
  536. JsonService::success('修改成功');
  537. } else {
  538. SystemStoreSender::rollbackTrans();
  539. JsonService::fail('修改失败或者您没有修改什么!');
  540. }
  541. } else {
  542. $data['add_time'] = time();
  543. $data['is_show'] = 1;
  544. if ($res = SystemStoreSender::create($data)) {
  545. SystemStoreSender::commitTrans();
  546. JsonService::success('保存成功', ['id' => $res->id]);
  547. } else {
  548. SystemStoreSender::rollbackTrans();
  549. JsonService::fail('保存失败!');
  550. }
  551. }
  552. } catch (\Exception $e) {
  553. SystemStoreSender::rollbackTrans();
  554. JsonService::fail($e->getMessage());
  555. }
  556. }
  557. /**
  558. * 设置单个门店是否显示
  559. * @param string $is_show
  560. * @param string $id
  561. * @return json
  562. */
  563. public function set_sender_show($is_show = '', $id = '')
  564. {
  565. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  566. $res = SystemStoreSender::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  567. if ($res) {
  568. return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
  569. } else {
  570. return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
  571. }
  572. }
  573. /**
  574. * 删除恢复门店
  575. * @param $id
  576. */
  577. public function sender_delete($id)
  578. {
  579. if (!$id) return $this->failed('数据不存在');
  580. if (!SystemStoreSender::be(['id' => $id])) return $this->failed('数据不存在');
  581. if (SystemStoreSender::be(['id' => $id, 'is_del' => 1])) {
  582. $data['is_del'] = 0;
  583. if (!SystemStoreSender::edit($data, $id))
  584. return JsonService::fail(SystemStoreSender::getErrorInfo('恢复失败,请稍候再试!'));
  585. else
  586. return JsonService::successful('恢复成功!');
  587. } else {
  588. $data['is_del'] = 1;
  589. if (!SystemStoreSender::edit($data, $id))
  590. return JsonService::fail(SystemStoreSender::getErrorInfo('删除失败,请稍候再试!'));
  591. else
  592. return JsonService::successful('删除成功!');
  593. }
  594. }
  595. /**
  596. * 立即支付
  597. * @param $id
  598. */
  599. public function offline($id)
  600. {
  601. if (!$this->store_id) {
  602. JsonService::fail('未知门店');
  603. }
  604. $order = StoreOrder::get($id);
  605. if ($order['store_id'] != $this->store_id) {
  606. JsonService::fail('订单门店异常');
  607. }
  608. $res = StoreOrderModel::updateOffline($id);
  609. if ($res) {
  610. event('StoreProductOrderOffline', [$id]);
  611. StoreOrderStatus::setStatus($id, 'offline', '线下付款');
  612. return JsonService::successful('修改成功!');
  613. } else {
  614. return JsonService::fail(StoreOrderModel::getErrorInfo('修改失败!'));
  615. }
  616. }
  617. //TODO 库存管理
  618. }