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 库存管理 }