SystemStore.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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\system\SystemStoreBill;
  7. use app\admin\model\system\SystemStoreExtract;
  8. use app\admin\model\ump\StorePink;
  9. use app\admin\model\user\User;
  10. use crmeb\repositories\OrderRepository;
  11. use crmeb\services\FormBuilder;
  12. use crmeb\services\JsonService;
  13. use app\admin\model\system\SystemStore as SystemStoreModel;
  14. use crmeb\services\UtilService;
  15. use Exception;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. use think\facade\Route;
  20. use think\facade\Session;
  21. /**
  22. * 门店后台控制器
  23. * Class SystemAttachment
  24. * @package app\admin\controller\system
  25. *
  26. */
  27. class SystemStore extends AuthController
  28. {
  29. private $store_id;
  30. public function initialize()
  31. {
  32. parent::initialize(); // TODO: Change the autogenerated stub
  33. $this->store_id = Session::get('store_id', 0);
  34. if ($this->storeId) $this->store_id = $this->storeId;
  35. }
  36. /**
  37. * 门店列表
  38. * @throws Exception
  39. */
  40. public function list()
  41. {
  42. $where = UtilService::getMore([
  43. ['page', 1],
  44. ['limit', 20],
  45. ['name', ''],
  46. ['level', ''],
  47. ['excel', 0],
  48. ['parent_id', $this->request->param('pid', '')],
  49. ['type', $this->request->param('type')]
  50. ]);
  51. JsonService::successlayui(SystemStoreModel::getStoreList($where));
  52. }
  53. /**
  54. * 选择门店
  55. * @param string $origin
  56. * @return string
  57. * @throws Exception
  58. */
  59. public function index($origin = '')
  60. {
  61. // var_dump($origin);
  62. // Session::delete('store_id');
  63. if ($this->storeId) {
  64. $this->redirect($origin ?: 'order');
  65. }
  66. if ($this->request->get('store_id', 0)) {
  67. Session::set('store_id', $this->request->get('store_id', 0));
  68. $this->redirect($origin ?: 'index');
  69. }
  70. $type = $this->request->param('type');
  71. $show = SystemStoreModel::where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
  72. $hide = SystemStoreModel::where('is_show', 0)->count();//隐藏的门店
  73. $recycle = SystemStoreModel::where('is_del', 1)->count();//删除的门店
  74. if ($type == null) $type = 1;
  75. // $this->assign('pid', $this->request->get('pid', 0));
  76. $this->assign(compact('type', 'show', 'hide', 'recycle'));
  77. $this->assign('origin', url($origin ?: 'index'));
  78. // $this->assign('level_list', $new);
  79. return $this->fetch();
  80. }
  81. /**
  82. * @return string
  83. * @throws Exception
  84. */
  85. public function order()
  86. {
  87. // var_dump($this->storeId);
  88. if (!$this->store_id) {
  89. $this->redirect(url('index', array('origin' => 'order'))->build());
  90. }
  91. $this->assign([
  92. 'year' => get_month(),
  93. 'store_name' => SystemStoreModel::get($this->store_id)['name'],
  94. 'real_name' => $this->request->get('real_name', ''),
  95. 'status' => $this->request->param('status', ''),
  96. 'orderCount' => StoreOrderModel::orderCount($this->store_id),
  97. 'payTypeCount' => StoreOrderModel::payTypeCount($this->store_id),
  98. ]);
  99. $this->assign('store_id', $this->store_id);
  100. return $this->fetch();
  101. }
  102. /**
  103. * 核销码核销
  104. * @param string $verify_code
  105. * @param int $is_confirm
  106. * @return string
  107. * @throws DataNotFoundException
  108. * @throws DbException
  109. * @throws ModelNotFoundException
  110. * @throws Exception
  111. */
  112. public function write_order($verify_code = '', $is_confirm = 0)
  113. {
  114. if ($this->request->isAjax()) {
  115. if (!$this->store_id) {
  116. JsonService::fail('未知门店');
  117. }
  118. if (!$verify_code) JsonService::fail('缺少核销码!');
  119. StoreOrderModel::beginTrans();
  120. $orderInfo = StoreOrderModel::where('store_id', $this->store_id)->where('verify_code', $verify_code)->where('paid', 1)->where('refund_status', 0)->find();
  121. if (!$orderInfo) JsonService::fail('核销订单不存在!');
  122. if ($orderInfo->status > 0) JsonService::fail('订单已核销!');
  123. if ($orderInfo->combination_id && $orderInfo->pink_id) {
  124. $res = StorePink::where('id', $orderInfo->pink_id)->where('status', '<>', 2)->count();
  125. if ($res) JsonService::fail('拼团订单暂未成功无法核销!');
  126. }
  127. if ($is_confirm == 0) {
  128. $orderInfo['nickname'] = User::where(['uid' => $orderInfo['uid']])->value('nickname');
  129. JsonService::successful($orderInfo);
  130. }
  131. $orderInfo->status = 2;
  132. if ($orderInfo->save()) {
  133. OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo);
  134. StoreOrderStatus::setStatus($orderInfo->id, 'take_delivery', '已核销');
  135. //发送短信
  136. event('ShortMssageSend', [$orderInfo['order_id'], 'Receiving']);
  137. StoreOrderModel::commitTrans();
  138. JsonService::successful('核销成功!');
  139. } else {
  140. StoreOrderModel::rollbackTrans();
  141. JsonService::fail('核销失败');
  142. }
  143. } else {
  144. if (!$this->store_id) {
  145. $this->redirect(url('index', array('origin' => 'order'))->build());
  146. }
  147. $this->assign('is_layui', 1);
  148. return $this->fetch();
  149. }
  150. }
  151. /**
  152. * 获取订单列表
  153. * return json
  154. */
  155. public function order_list()
  156. {
  157. if (!$this->store_id) {
  158. JsonService::fail('未知门店');
  159. }
  160. $where = UtilService::getMore([
  161. ['status', ''],
  162. ['real_name', $this->request->param('real_name', '')],
  163. ['is_del', 0],
  164. ['data', ''],
  165. ['type', ''],
  166. ['pay_type', ''],
  167. ['order', ''],
  168. ['page', 1],
  169. ['limit', 20],
  170. ['excel', 0]
  171. ]);
  172. $where['store_id'] = $this->store_id;
  173. JsonService::successlayui(StoreOrderModel::OrderList($where));
  174. }
  175. /**
  176. *
  177. */
  178. public function getOrderBadge()
  179. {
  180. if (!$this->store_id) {
  181. JsonService::fail('未知门店');
  182. }
  183. $where = UtilService::postMore([
  184. ['status', ''],
  185. ['real_name', ''],
  186. ['is_del', 0],
  187. ['data', ''],
  188. ['type', ''],
  189. ['pay_type', ''],
  190. ['order', '']
  191. ]);
  192. $where['store_id'] = $this->store_id;
  193. JsonService::successful(StoreOrderModel::getBadge($where));
  194. }
  195. /**
  196. * @return string
  197. * @throws Exception
  198. */
  199. public function bill()
  200. {
  201. if (!$this->store_id) {
  202. $this->redirect(url('index', array('origin' => 'bill'))->build());
  203. }
  204. $this->assign('store_info', SystemStoreModel::get($this->store_id));
  205. $this->assign('id', $this->store_id);
  206. return $this->fetch();
  207. }
  208. public function store_bill_log_list($id)
  209. {
  210. $where = UtilService::getMore([
  211. ['page', 1],
  212. ['limit', 20],
  213. ]);
  214. JsonService::successlayui(SystemStoreBill::getList($where, $id));
  215. }
  216. /**
  217. * @return string
  218. * @throws Exception
  219. */
  220. public function cash()
  221. {
  222. if (!$this->store_id) {
  223. $this->redirect(url('index', array('origin' => 'cash'))->build());
  224. }
  225. $store_info = SystemStoreModel::get($this->store_id);
  226. $f = array();
  227. $f[] = FormBuilder::radio('extract_type', '提现方式', 'bank')->setOptions([['label' => '银行', 'value' => 'bank'],
  228. // ['label' => '支付宝', 'value' => 'alipay'], ['label' => '微信', 'value' => 'weixin']
  229. ]);
  230. $f[] = FormBuilder::number('money', '提现金额', 0)->col(24)->step(0.01)->min(0)->max($store_info['brokerage_price']);
  231. $f[] = FormBuilder::input('name', '姓名', $store_info['leader']);
  232. $f[] = FormBuilder::input('bankname', '开户银行', $store_info['bank_name']);
  233. $f[] = FormBuilder::input('cardnum', '银行卡号', $store_info['bank_card']);
  234. // $f[] = FormBuilder::input('alipay_code', '支付宝账号');
  235. // $f[] = FormBuilder::input('weixin', '微信号');
  236. $form = FormBuilder::make_post_form('发起提现', $f, Route::buildUrl('cash_save'));
  237. $this->assign(compact('form'));
  238. return $this->fetch('public/form-builder');
  239. }
  240. /**
  241. * 提现申请
  242. */
  243. public function cash_save()
  244. {
  245. if (!$this->store_id) {
  246. JsonService::fail('店铺异常');
  247. }
  248. $extractInfo = UtilService::postMore([
  249. ['alipay_code', ''],
  250. ['extract_type', ''],
  251. ['money', 0],
  252. ['name', ''],
  253. ['bankname', ''],
  254. ['cardnum', ''],
  255. ['weixin', ''],
  256. ], $this->request);
  257. if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) JsonService::fail('提现金额输入有误');
  258. $store = SystemStoreModel::get($this->store_id);
  259. if ($extractInfo['money'] > $store['brokerage_price']) JsonService::fail('可提现佣金不足');
  260. if (!$extractInfo['cardnum'] == '')
  261. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  262. JsonService::fail('银行卡号输入有误');
  263. if (SystemStoreExtract::userExtract($store, $extractInfo))
  264. JsonService::successful('申请提现成功!');
  265. else
  266. JsonService::fail(SystemStoreExtract::getErrorInfo('提现失败'));
  267. }
  268. /**
  269. * @return string
  270. * @throws Exception
  271. */
  272. public function info()
  273. {
  274. if (!$this->store_id) {
  275. $this->redirect(url('index', array('origin' => 'info'))->build());
  276. }
  277. $this->assign('store_info', SystemStoreModel::getStoreInfo($this->store_id) ?: []);
  278. return $this->fetch();
  279. }
  280. //TODO 自提点管理
  281. //TODO 库存管理
  282. }