123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <?php
- namespace app\admin\controller\merchant;
- use app\admin\controller\AuthController;
- use app\admin\model\order\StoreOrder as StoreOrderModel;
- use app\admin\model\order\StoreOrderStatus;
- use app\admin\model\system\SystemStoreBill;
- use app\admin\model\system\SystemStoreExtract;
- use app\admin\model\ump\StorePink;
- use app\admin\model\user\User;
- use crmeb\repositories\OrderRepository;
- use crmeb\services\FormBuilder;
- use crmeb\services\JsonService;
- use app\admin\model\system\SystemStore as SystemStoreModel;
- use crmeb\services\UtilService;
- use Exception;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\facade\Route;
- use think\facade\Session;
- /**
- * 门店后台控制器
- * Class SystemAttachment
- * @package app\admin\controller\system
- *
- */
- class SystemStore extends AuthController
- {
- private $store_id;
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- $this->store_id = Session::get('store_id', 0);
- if ($this->storeId) $this->store_id = $this->storeId;
- }
- /**
- * 门店列表
- * @throws Exception
- */
- public function list()
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ['name', ''],
- ['level', ''],
- ['excel', 0],
- ['parent_id', $this->request->param('pid', '')],
- ['type', $this->request->param('type')]
- ]);
- JsonService::successlayui(SystemStoreModel::getStoreList($where));
- }
- /**
- * 选择门店
- * @param string $origin
- * @return string
- * @throws Exception
- */
- public function index($origin = '')
- {
- // var_dump($origin);
- // Session::delete('store_id');
- if ($this->storeId) {
- $this->redirect($origin ?: 'order');
- }
- if ($this->request->get('store_id', 0)) {
- Session::set('store_id', $this->request->get('store_id', 0));
- $this->redirect($origin ?: 'index');
- }
- $type = $this->request->param('type');
- $show = SystemStoreModel::where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
- $hide = SystemStoreModel::where('is_show', 0)->count();//隐藏的门店
- $recycle = SystemStoreModel::where('is_del', 1)->count();//删除的门店
- if ($type == null) $type = 1;
- // $this->assign('pid', $this->request->get('pid', 0));
- $this->assign(compact('type', 'show', 'hide', 'recycle'));
- $this->assign('origin', url($origin ?: 'index'));
- // $this->assign('level_list', $new);
- return $this->fetch();
- }
- /**
- * @return string
- * @throws Exception
- */
- public function order()
- {
- // var_dump($this->storeId);
- if (!$this->store_id) {
- $this->redirect(url('index', array('origin' => 'order'))->build());
- }
- $this->assign([
- 'year' => get_month(),
- 'store_name' => SystemStoreModel::get($this->store_id)['name'],
- 'real_name' => $this->request->get('real_name', ''),
- 'status' => $this->request->param('status', ''),
- 'orderCount' => StoreOrderModel::orderCount($this->store_id),
- 'payTypeCount' => StoreOrderModel::payTypeCount($this->store_id),
- ]);
- $this->assign('store_id', $this->store_id);
- return $this->fetch();
- }
- /**
- * 核销码核销
- * @param string $verify_code
- * @param int $is_confirm
- * @return string
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @throws Exception
- */
- public function write_order($verify_code = '', $is_confirm = 0)
- {
- if ($this->request->isAjax()) {
- if (!$this->store_id) {
- JsonService::fail('未知门店');
- }
- if (!$verify_code) JsonService::fail('缺少核销码!');
- StoreOrderModel::beginTrans();
- $orderInfo = StoreOrderModel::where('store_id', $this->store_id)->where('verify_code', $verify_code)->where('paid', 1)->where('refund_status', 0)->find();
- if (!$orderInfo) JsonService::fail('核销订单不存在!');
- if ($orderInfo->status > 0) JsonService::fail('订单已核销!');
- if ($orderInfo->combination_id && $orderInfo->pink_id) {
- $res = StorePink::where('id', $orderInfo->pink_id)->where('status', '<>', 2)->count();
- if ($res) JsonService::fail('拼团订单暂未成功无法核销!');
- }
- if ($is_confirm == 0) {
- $orderInfo['nickname'] = User::where(['uid' => $orderInfo['uid']])->value('nickname');
- JsonService::successful($orderInfo);
- }
- $orderInfo->status = 2;
- if ($orderInfo->save()) {
- OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo);
- StoreOrderStatus::setStatus($orderInfo->id, 'take_delivery', '已核销');
- //发送短信
- event('ShortMssageSend', [$orderInfo['order_id'], 'Receiving']);
- StoreOrderModel::commitTrans();
- JsonService::successful('核销成功!');
- } else {
- StoreOrderModel::rollbackTrans();
- JsonService::fail('核销失败');
- }
- } else {
- if (!$this->store_id) {
- $this->redirect(url('index', array('origin' => 'order'))->build());
- }
- $this->assign('is_layui', 1);
- return $this->fetch();
- }
- }
- /**
- * 获取订单列表
- * return json
- */
- public function order_list()
- {
- if (!$this->store_id) {
- JsonService::fail('未知门店');
- }
- $where = UtilService::getMore([
- ['status', ''],
- ['real_name', $this->request->param('real_name', '')],
- ['is_del', 0],
- ['data', ''],
- ['type', ''],
- ['pay_type', ''],
- ['order', ''],
- ['page', 1],
- ['limit', 20],
- ['excel', 0]
- ]);
- $where['store_id'] = $this->store_id;
- JsonService::successlayui(StoreOrderModel::OrderList($where));
- }
- /**
- *
- */
- public function getOrderBadge()
- {
- if (!$this->store_id) {
- JsonService::fail('未知门店');
- }
- $where = UtilService::postMore([
- ['status', ''],
- ['real_name', ''],
- ['is_del', 0],
- ['data', ''],
- ['type', ''],
- ['pay_type', ''],
- ['order', '']
- ]);
- $where['store_id'] = $this->store_id;
- JsonService::successful(StoreOrderModel::getBadge($where));
- }
- /**
- * @return string
- * @throws Exception
- */
- public function bill()
- {
- if (!$this->store_id) {
- $this->redirect(url('index', array('origin' => 'bill'))->build());
- }
- $this->assign('store_info', SystemStoreModel::get($this->store_id));
- $this->assign('id', $this->store_id);
- return $this->fetch();
- }
- public function store_bill_log_list($id)
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- JsonService::successlayui(SystemStoreBill::getList($where, $id));
- }
- /**
- * @return string
- * @throws Exception
- */
- public function cash()
- {
- if (!$this->store_id) {
- $this->redirect(url('index', array('origin' => 'cash'))->build());
- }
- $store_info = SystemStoreModel::get($this->store_id);
- $f = array();
- $f[] = FormBuilder::radio('extract_type', '提现方式', 'bank')->setOptions([['label' => '银行', 'value' => 'bank'],
- // ['label' => '支付宝', 'value' => 'alipay'], ['label' => '微信', 'value' => 'weixin']
- ]);
- $f[] = FormBuilder::number('money', '提现金额', 0)->col(24)->step(0.01)->min(0)->max($store_info['brokerage_price']);
- $f[] = FormBuilder::input('name', '姓名', $store_info['leader']);
- $f[] = FormBuilder::input('bankname', '开户银行', $store_info['bank_name']);
- $f[] = FormBuilder::input('cardnum', '银行卡号', $store_info['bank_card']);
- // $f[] = FormBuilder::input('alipay_code', '支付宝账号');
- // $f[] = FormBuilder::input('weixin', '微信号');
- $form = FormBuilder::make_post_form('发起提现', $f, Route::buildUrl('cash_save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 提现申请
- */
- public function cash_save()
- {
- if (!$this->store_id) {
- JsonService::fail('店铺异常');
- }
- $extractInfo = UtilService::postMore([
- ['alipay_code', ''],
- ['extract_type', ''],
- ['money', 0],
- ['name', ''],
- ['bankname', ''],
- ['cardnum', ''],
- ['weixin', ''],
- ], $this->request);
- if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) JsonService::fail('提现金额输入有误');
- $store = SystemStoreModel::get($this->store_id);
- if ($extractInfo['money'] > $store['brokerage_price']) JsonService::fail('可提现佣金不足');
- if (!$extractInfo['cardnum'] == '')
- if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
- JsonService::fail('银行卡号输入有误');
- if (SystemStoreExtract::userExtract($store, $extractInfo))
- JsonService::successful('申请提现成功!');
- else
- JsonService::fail(SystemStoreExtract::getErrorInfo('提现失败'));
- }
- /**
- * @return string
- * @throws Exception
- */
- public function info()
- {
- if (!$this->store_id) {
- $this->redirect(url('index', array('origin' => 'info'))->build());
- }
- $this->assign('store_info', SystemStoreModel::getStoreInfo($this->store_id) ?: []);
- return $this->fetch();
- }
- //TODO 自提点管理
- //TODO 库存管理
- }
|