request->param('type')] ]); JsonService::successlayui(SystemStoreModel::getStoreList($where)); } /** * 门店设置 * @return string */ public function 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(compact('type', 'show', 'hide', 'recycle')); return $this->fetch(); } /** * 门店添加 * @param int $id * @return string */ public function add($id = 0) { $store = SystemStoreModel::getStoreDispose($id); $this->assign(compact('store')); return $this->fetch(); } /** * 删除恢复门店 * @param $id */ public function delete($id) { if (!$id) return $this->failed('数据不存在'); if (!SystemStoreModel::be(['id' => $id])) return $this->failed('产品数据不存在'); if (SystemStoreModel::be(['id' => $id, 'is_del' => 1])) { $data['is_del'] = 0; if (!SystemStoreModel::edit($data, $id)) return Json::fail(SystemStoreModel::getErrorInfo('恢复失败,请稍候再试!')); else return Json::successful('恢复门店成功!'); } else { $data['is_del'] = 1; if (!SystemStoreModel::edit($data, $id)) return Json::fail(SystemStoreModel::getErrorInfo('删除失败,请稍候再试!')); else return Json::successful('删除门店成功!'); } } /** * 设置单个门店是否显示 * @param string $is_show * @param string $id * @return json */ public function set_show($is_show = '', $id = '') { ($is_show == '' || $id == '') && JsonService::fail('缺少参数'); $res = SystemStoreModel::where(['id' => $id])->update(['is_show' => (int)$is_show]); if ($res) { return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功'); } else { return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败'); } } /** * 位置选择 * @return string|void */ public function select_address() { $key = sys_config('tengxun_map_key'); if (!$key) return $this->failed('请前往设置->物流设置->物流配置 配置腾讯地图KEY', '#'); $this->assign(compact('key')); return $this->fetch(); } /** * 保存修改门店信息 * @param int $id */ public function save($id = 0) { $data = UtilService::postMore([ ['name', ''], ['introduction', ''], ['image', ''], ['phone', ''], ['address', ''], ['detailed_address', ''], ['latlng', ''], ['valid_time', []], ['day_time', []], ['radius', 0], ['leader', ''], ['pictures', []], ['recharge_award_ratio', 0], ['terminal_number', ''], ['sh_start_money', 0], ['sh_start_distance', 0], ['sh_step', 0], ['sh_step_money', 0], ['sharing', 0], ['store_user', 0], ['see', 0], ['pay', 0], ]); SystemStoreModel::beginTrans(); try { $data['address'] = implode(',', $data['address']); $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng']; if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) JsonService::fail('请选择门店位置'); if ($data['sh_step'] <= 0) JsonService::fail('超过距离基数不能小于等于0'); $data['latitude'] = $data['latlng'][0]; $data['longitude'] = $data['latlng'][1]; $data['valid_time'] = implode(' - ', $data['valid_time']); $data['day_time'] = implode(' - ', $data['day_time']); unset($data['latlng']); if ($data['image'] && strstr($data['image'], 'http') === false) { $site_url = sys_config('site_url'); $data['image'] = $site_url . $data['image']; } $new = []; foreach ($data['pictures'] as $v) { $site_url = sys_config('site_url'); $new[] = $site_url . $v; } $data['pictures'] = implode(',', $new); if ($id) { if (SystemStoreModel::where('id', $id)->update($data)) { SystemStoreModel::commitTrans(); JsonService::success('修改成功'); } else { SystemStoreModel::rollbackTrans(); JsonService::fail('修改失败或者您没有修改什么!'); } } else { $data['add_time'] = time(); $data['is_show'] = 1; if ($res = SystemStoreModel::create($data)) { SystemAdmin::create([ 'account' => 'store_admin_' . $res->id, 'pwd' => md5('123456'), 'real_name' => $data['leader'], 'roles' => sys_config('default_store_admin', 7), 'add_time' => time(), 'status' => 1, 'level' => 2, 'store_id' => $res->id, ]); SystemStoreModel::commitTrans(); JsonService::success('保存成功', ['id' => $res->id]); } else { SystemStoreModel::rollbackTrans(); JsonService::fail('保存失败!'); } } } catch (\Exception $e) { SystemStoreModel::rollbackTrans(); JsonService::fail($e->getMessage()); } } /** * @param $id * @return string * @throws Exception */ public function storeProductInfo($id) { $this->assign('id', $id); $this->assign('year', get_month()); return $this->fetch(); } public function stock_list($id) { $where = UtilService::getMore([ ['page', 1], ['data', ''], ['limit', 20], ['product_id', ''], ['excel', 0], ]); JsonService::successlayui(SystemStoreProductStock::getStockList($where, $id)); } public function add_stock($id) { if (!$id) { return $this->failed('请选择门店'); } $where = UtilService::getMore([ ['product_id', 0], ['unique', ''], ]); if (!$where['product_id'] || !$where['unique']) { $field = []; $field[] = FormBuilder::frameImages('product', '选择商品', Route::buildUrl('productList', array('fodder' => 'product')))->icon('plus')->width('100%')->height('500px'); $field[] = FormBuilder::hidden('product_id', ''); $field[] = FormBuilder::number('price', '价格', 0)->step(0.01); $field[] = FormBuilder::hidden('unique', ''); } else { $field = []; $field[] = FormBuilder::hidden('product_id', $where['product_id']); $field[] = FormBuilder::number('price', '价格', SystemStoreProductStock::where(['product_id' => $where['product_id'], 'unique' => $where['unique'], 'store_id' => $id])->value('price'))->step(0.01); $field[] = FormBuilder::hidden('unique', $where['unique']); } $field[] = FormBuilder::number('stock', '库存增加量', 0); $form = FormBuilder::make_post_form('添加库存', $field, Route::buildUrl('save_stock', ['id' => $id]), 3); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /** * @return string * @throws DataNotFoundException * @throws ModelNotFoundException * @throws Exception */ public function productList() { $cate = StoreCategory::getTierList(null, 1); $this->assign('cate', $cate); return $this->fetch(); } public function save_stock($id) { if (!$id) { Json::fail('请选择门店'); } list($product_id, $unique, $stock, $price) = UtilService::postMore([['product_id', []], ['unique', []], ['stock', 0], ['price', 0]], $this->request, true); if (!count($product_id)) { Json::fail('请选择补货商品'); } $res = true; SystemStoreProductStockLog::beginTrans(); foreach ($product_id as $k => $v) { if ($stock > 0) { $res = $res && SystemStoreProductStockLog::income($id, $v, $unique[$k], 'add_stock', 0, $stock, $this->adminId, '后台补货' . $stock . '件', 1, $price); } else { $res = $res && SystemStoreProductStockLog::expend($id, $v, $unique[$k], 'dec_stock', 0, abs($stock), $this->adminId, '后台减货' . $stock . '件', 1, $price); } } if ($res) { SystemStoreProductStockLog::commitTrans(); Json::success('补货成功'); } else { SystemStoreProductStockLog::rollbackTrans(); Json::fail(SystemStoreProductStockLog::getErrorInfo('补货失败')); } } /** * @param $id * @return string * @throws Exception */ public function stock_log($id) { $this->assign('id', $id); return $this->fetch(); } public function stock_log_list($id) { $where = UtilService::getMore([ ['page', 1], ['limit', 20], ]); JsonService::successlayui(SystemStoreProductStockLog::getList($where, $id)); } /** * @param $id * @return string * @throws Exception */ public function store_bill_log($id) { $this->assign('id', $id); $this->assign('all', SystemStoreModel::get($id)['brokerage_price']); return $this->fetch(); } public function store_bill_log_list($id) { $where = UtilService::getMore([ ['page', 1], ['limit', 20], ]); JsonService::successlayui(SystemStoreBill::getList($where, $id)); } /** * @param $id * @return string * @throws Exception */ public function store_point($id) { $type = $this->request->param('type'); $show = SystemStorePoint::where('store_id', $id)->where('is_show', 1)->where('is_del', 0)->count();//显示中的门店 $hide = SystemStorePoint::where('store_id', $id)->where('is_show', 0)->count();//隐藏的门店 $recycle = SystemStorePoint::where('store_id', $id)->where('is_del', 1)->count();//删除的门店 if ($type == null) $type = 1; $this->assign(compact('type', 'show', 'hide', 'recycle', 'id')); return $this->fetch(); } public function store_point_list($id) { $where = UtilService::getMore([ ['page', 1], ['limit', 20], ['name', ''], ['excel', 0], ['type', $this->request->param('type')] ]); $where['store_id'] = $id; JsonService::successlayui(SystemStorePoint::getStoreList($where)); } /** * 门店添加 * @param int $id * @return string */ public function add_point($id = 0, $store_id = 0) { $store = SystemStorePoint::getStoreDispose($id); $this->assign(compact('store', 'store_id')); return $this->fetch(); } /** * 保存修改门店信息 * @param int $id */ public function save_point($id = 0) { $data = UtilService::postMore([ ['name', ''], ['phone', ''], ['address', ''], ['detailed_address', ''], ['latlng', ''], ['valid_time', []], ['day_time', []], ['store_id', 0], ]); // var_dump($data['store_id']); if (!$data['store_id'] || !SystemStoreModel::getStoreDispose($data['store_id'])) JsonService::fail('无效门店'); SystemStorePoint::beginTrans(); try { $data['address'] = implode(',', $data['address']); $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng']; if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) JsonService::fail('请选择门店位置'); $data['latitude'] = $data['latlng'][0]; $data['longitude'] = $data['latlng'][1]; $data['valid_time'] = implode(' - ', $data['valid_time']); $data['day_time'] = implode(' - ', $data['day_time']); unset($data['latlng']); if ($id) { if (SystemStorePoint::where('id', $id)->update($data)) { SystemStorePoint::commitTrans(); JsonService::success('修改成功'); } else { SystemStorePoint::rollbackTrans(); JsonService::fail('修改失败或者您没有修改什么!'); } } else { $data['add_time'] = time(); $data['is_show'] = 1; if ($res = SystemStorePoint::create($data)) { SystemStorePoint::commitTrans(); JsonService::success('保存成功', ['id' => $res->id]); } else { SystemStorePoint::rollbackTrans(); JsonService::fail('保存失败!'); } } } catch (\Exception $e) { SystemStorePoint::rollbackTrans(); JsonService::fail($e->getMessage()); } } /** * 设置单个门店是否显示 * @param string $is_show * @param string $id * @return json */ public function set_point_show($is_show = '', $id = '') { ($is_show == '' || $id == '') && JsonService::fail('缺少参数'); $res = SystemStorePoint::where(['id' => $id])->update(['is_show' => (int)$is_show]); if ($res) { return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功'); } else { return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败'); } } /** * 删除恢复门店 * @param $id */ public function point_delete($id) { if (!$id) return $this->failed('数据不存在'); if (!SystemStorePoint::be(['id' => $id])) return $this->failed('数据不存在'); if (SystemStorePoint::be(['id' => $id, 'is_del' => 1])) { $data['is_del'] = 0; if (!SystemStorePoint::edit($data, $id)) return Json::fail(SystemStorePoint::getErrorInfo('恢复失败,请稍候再试!')); else return Json::successful('恢复门店成功!'); } else { $data['is_del'] = 1; if (!SystemStorePoint::edit($data, $id)) return Json::fail(SystemStorePoint::getErrorInfo('删除失败,请稍候再试!')); else return Json::successful('删除门店成功!'); } } /** * @param $id * @return string * @throws Exception */ public function store_sender($id) { $type = $this->request->param('type'); $show = SystemStoreSender::where('store_id', $id)->where('is_show', 1)->where('is_del', 0)->count();//显示中的门店 $hide = SystemStoreSender::where('store_id', $id)->where('is_show', 0)->count();//隐藏的门店 $recycle = SystemStoreSender::where('store_id', $id)->where('is_del', 1)->count();//删除的门店 if ($type == null) $type = 1; $this->assign(compact('type', 'show', 'hide', 'recycle', 'id')); return $this->fetch(); } public function store_sender_list($id) { $where = UtilService::getMore([ ['page', 1], ['limit', 20], ['name', ''], ['excel', 0], ['type', $this->request->param('type')] ]); $where['store_id'] = $id; JsonService::successlayui(SystemStoreSender::getStoreList($where)); } /** * 门店添加 * @param int $id * @return string */ public function add_sender($id = 0, $store_id = 0) { $store = SystemStoreSender::getStoreDispose($id); $this->assign(compact('store', 'store_id')); return $this->fetch(); } /** * 保存修改门店信息 * @param int $id */ public function save_sender($id = 0) { $data = UtilService::postMore([ ['name', ''], ['phone', ''], ['store_id', 0], ]); // var_dump($data['store_id']); if (!$data['store_id'] || !SystemStoreModel::getStoreDispose($data['store_id'])) JsonService::fail('无效门店'); SystemStoreSender::beginTrans(); try { if ($id) { if (SystemStoreSender::where('id', $id)->update($data)) { SystemStoreSender::commitTrans(); JsonService::success('修改成功'); } else { SystemStoreSender::rollbackTrans(); JsonService::fail('修改失败或者您没有修改什么!'); } } else { $data['add_time'] = time(); $data['is_show'] = 1; if ($res = SystemStoreSender::create($data)) { SystemStoreSender::commitTrans(); JsonService::success('保存成功', ['id' => $res->id]); } else { SystemStoreSender::rollbackTrans(); JsonService::fail('保存失败!'); } } } catch (\Exception $e) { SystemStoreSender::rollbackTrans(); JsonService::fail($e->getMessage()); } } /** * 设置单个门店是否显示 * @param string $is_show * @param string $id * @return json */ public function set_sender_show($is_show = '', $id = '') { ($is_show == '' || $id == '') && JsonService::fail('缺少参数'); $res = SystemStoreSender::where(['id' => $id])->update(['is_show' => (int)$is_show]); if ($res) { return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功'); } else { return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败'); } } /** * 删除恢复门店 * @param $id */ public function sender_delete($id) { if (!$id) return $this->failed('数据不存在'); if (!SystemStoreSender::be(['id' => $id])) return $this->failed('数据不存在'); if (SystemStoreSender::be(['id' => $id, 'is_del' => 1])) { $data['is_del'] = 0; if (!SystemStoreSender::edit($data, $id)) return Json::fail(SystemStoreSender::getErrorInfo('恢复失败,请稍候再试!')); else return Json::successful('恢复门店成功!'); } else { $data['is_del'] = 1; if (!SystemStoreSender::edit($data, $id)) return Json::fail(SystemStoreSender::getErrorInfo('删除失败,请稍候再试!')); else return Json::successful('删除门店成功!'); } } }