diff --git a/app/admin/controller/distribution/DistributionPartner.php b/app/admin/controller/distribution/DistributionPartner.php new file mode 100755 index 00000000..879c10d6 --- /dev/null +++ b/app/admin/controller/distribution/DistributionPartner.php @@ -0,0 +1,116 @@ +request->isAjax()){ + $get = $this->request->get(); + if ($get['type'] == 1) { // 店铺类型 + $list = DistributionStoreTypeLogic::templatelists($get); + } else { + $list = DistributionStoreTypeLogic::getConfig(); + } + return JsonServer::success('', $list); + } + return view(); + } + + public function add(){ + if ($this->request->isAjax()){ + $post = $this->request->post(); + $result = DistributionPartnerLogic::add($post); + if ($result === true){ + return JsonServer::success('新增成功'); + } + return JsonServer::error(DistributionStoreTypeLogic::getError()); + } + + $city = DevRegion::where(['level'=>2]) + ->field('id,name') + ->select() + ->toArray(); + + return view('', [ + 'city' => $city, + 'partner' => DistributionPartnerEnum::getPartner() + ]); + } + + public function changeFields(){ + $id = $this->request->get('id'); + + $field = $this->request->get('field'); + $value = $this->request->get('value'); + + if ($field === 'sort') { + $result = DistributionStoreTypeLogic::changeOrderValue($id, $value); + if($result){ + return JsonServer::success('修改成功'); + } + } + + return JsonServer::error('修改失败'); + } + + public function edit($id) + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + + try { + validate(DistributionStoreTypeValidate::class)->check($post); + } catch(ValidateException $e) { + return JsonServer::error($e->getError()); + } + + $result = DistributionStoreTypeLogic::edit($post); + + if ($result === true){ + return JsonServer::success('编辑成功'); + } + return JsonServer::error('编辑失败'); + } + + $info = DistributionStoreTypeLogic::getRechargeTemplate($id); + return view('', [ + 'info' => $info + ]); + } + + public function del($id) + { + if ($this->request->isAjax()) { + $result = DistributionStoreTypeLogic::del($id); + if ($result) { + return JsonServer::success('删除成功'); + } + return JsonServer::error('删除失败'); + } + } + + public function setStoreType(){ + if($this->request->isAjax()){ + $post = $this->request->post(); + + DistributionStoreTypeLogic::setStoreType($post); + return JsonServer::success('设置成功'); + } + } +} \ No newline at end of file diff --git a/app/admin/logic/distribution/DistributionPartnerLogic.php b/app/admin/logic/distribution/DistributionPartnerLogic.php new file mode 100755 index 00000000..d04ec8a2 --- /dev/null +++ b/app/admin/logic/distribution/DistributionPartnerLogic.php @@ -0,0 +1,99 @@ + 0]) + ->order(['sort' => 'desc']) + ->paginate([ + 'page' => $get['page'] ?? 1, + 'list_rows' => $get['limit'] ?? 10, + 'var_page' => 'page' + ]) + ->toArray(); + + return $list; + } + + public static function getConfig(){ + $config = [ + 'open_store_type' => ConfigServer::get('distribution','store_type',0), + ]; + return [$config]; + } + + public static function add($post){ + try{ + $citys = explode(',', $post['citys']); + $cityIds = []; + foreach ($citys as &$v) { + $cityIds[] = RegionLogic::cityCoverId($v); + } + + DistributionPartner::create([ + 'proportion' => str_replace('%', '', $post['proportion']), + 'city' => implode(',', $cityIds), + 'type' => $post['type'], + 'core_city_money' => $post['core_city_money'], + 'un_core_city_money' => $post['un_core_city_money'], + 'is_show' => $post['is_show'], + 'create_time' => time(), + ]); + return true; + }catch(\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + public static function changeOrderValue($id, $value) + { + try { + DistributionStoreType::where('id', $id)->update([ + 'sort' => $value, + 'update_time' => time(), + ]); + return true; + } catch(\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + public static function getRechargeTemplate($id){ + return DistributionStoreType::where(['id' => $id])->find(); + } + + public static function edit($post){ + try{ + DistributionStoreType::update([ + 'id' => $post['id'], + 'title' => $post['title'], + 'money' => $post['money'], + 'sort' => $post['sort'], + 'update_time' => time(), + ]); + return true; + }catch(\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + public static function del($id){ + return DistributionStoreType::where(['id' => $id])->update(['update_time' => time(),'is_delete' => 1]); + } + + public static function setStoreType($post){ + ConfigServer::set('distribution','store_type', $post['open_store_type']); + } +} diff --git a/app/admin/view/distribution/distribution_partner/add.html b/app/admin/view/distribution/distribution_partner/add.html new file mode 100755 index 00000000..09e31e4f --- /dev/null +++ b/app/admin/view/distribution/distribution_partner/add.html @@ -0,0 +1,133 @@ +{layout name="layout2" /} + +