diff --git a/application/admin/controller/manystore/Index.php b/application/admin/controller/manystore/Index.php index d37f8fc..58f3b56 100644 --- a/application/admin/controller/manystore/Index.php +++ b/application/admin/controller/manystore/Index.php @@ -62,7 +62,48 @@ class Index extends Backend protected $error_auth = false; protected $qSwitch = true; - protected $qFields = ["user_id"]; + protected $qFields = ["user_id","name","address_detail","type","tel","legal_entity","shop_apply_id"]; + + + protected function checkAssemblyParameters(){ + if(!$this->qSwitch)return false; + //得到所有get参数 + $get = $this->request->get(); + //得到当前model所有字段 + + + $fields = $this->shopModel->getTableFields(); + +// $commonFields = (new Field())->getCommonFields(); +// var_dump($commonFields); + $fieldLists = $fields; +// foreach ($commonFields as $commonField) { +// if (!in_array($commonField['column_name'], $fields)) { +// $fieldLists[] = $commonField; +// } +// } + $q_fields = []; + + foreach ($get as $kay=>$getField) { + if (in_array($kay, $fieldLists) || in_array($kay, $this->qFields)) { + $q_fields[$kay] = $getField; + } + } + + + //将q_fields塞入模板中 + foreach ($q_fields as $k=>$v) { + //渲染站点配置 + $this->assign('q_'.$k, $v); + } + + foreach ($this->qFields as $k) { + //渲染站点配置 + if(!isset($q_fields[$k]))$this->assign('q_'.$k, ""); + } + + + } public function _initialize() @@ -740,6 +781,7 @@ class Index extends Backend Admin::where(array('admin_shop_id'=>$row['shop_id']))->update(['admin_shop_id'=>0]); Evaluate::where(array('shop_id'=>$row['shop_id']))->delete(); + \app\common\model\manystore\ShopApply::where(array('shop_id'=>$row['shop_id']))->update(['shop_id'=>0,'store_id'=>0]); if(!$result){ exception('商家信息删除失败'); } diff --git a/application/admin/controller/manystore/ShopApply.php b/application/admin/controller/manystore/ShopApply.php new file mode 100644 index 0000000..5eba6db --- /dev/null +++ b/application/admin/controller/manystore/ShopApply.php @@ -0,0 +1,73 @@ +model = new \app\admin\model\manystore\ShopApply; + $this->view->assign("typeList", $this->model->getTypeList()); + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + /** + * 查看 + */ + public function index() + { + //当前是否为关联查询 + $this->relationSearch = true; + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + $list = $this->model + ->with(['user','shop']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + + foreach ($list as $row) { + + $row->getRelation('user')->visible(['nickname','mobile','avatar']); + $row->getRelation('shop')->visible(['name','logo']); + } + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + } + return $this->view->fetch(); + } + +} diff --git a/application/admin/lang/zh-cn/manystore/shop_apply.php b/application/admin/lang/zh-cn/manystore/shop_apply.php new file mode 100644 index 0000000..f12fc91 --- /dev/null +++ b/application/admin/lang/zh-cn/manystore/shop_apply.php @@ -0,0 +1,20 @@ + '申请用户', + 'Type' => '类型', + 'Type 1' => '个人', + 'Type 2' => '机构', + 'Name' => '机构名称', + 'Realname' => '联系人姓名', + 'Mobile' => '联系电话', + 'Address' => '机构|授课地址', + 'Shop_id' => '申请的机构id', + 'Create_time' => '创建时间', + 'Update_time' => '修改时间', + 'User.nickname' => '昵称', + 'User.mobile' => '手机号', + 'User.avatar' => '头像', + 'Shop.name' => '店铺名称', + 'Shop.logo' => '品牌LOGO' +]; diff --git a/application/admin/model/manystore/ShopApply.php b/application/admin/model/manystore/ShopApply.php new file mode 100644 index 0000000..e9283cd --- /dev/null +++ b/application/admin/model/manystore/ShopApply.php @@ -0,0 +1,83 @@ + __('Type 1'), '2' => __('Type 2')]; + } + + + public function getTypeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['type']) ? $data['type'] : ''); + $list = $this->getTypeList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + + public function getCreateTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + + public function getUpdateTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + protected function setCreateTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + protected function setUpdateTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + + public function user() + { + return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + + public function shop() + { + return $this->belongsTo(Shop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0); + } +} diff --git a/application/admin/validate/manystore/ShopApply.php b/application/admin/validate/manystore/ShopApply.php new file mode 100644 index 0000000..b607da9 --- /dev/null +++ b/application/admin/validate/manystore/ShopApply.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/manystore/index/add.html b/application/admin/view/manystore/index/add.html index d55e71d..1dab7ab 100644 --- a/application/admin/view/manystore/index/add.html +++ b/application/admin/view/manystore/index/add.html @@ -11,6 +11,9 @@
+ + +
@@ -78,7 +81,7 @@ @@ -89,7 +92,7 @@
- +
@@ -162,7 +165,7 @@
- +
@@ -213,7 +216,7 @@
- +
@@ -262,7 +265,7 @@
- +
diff --git a/application/admin/view/manystore/shop_apply/add.html b/application/admin/view/manystore/shop_apply/add.html new file mode 100644 index 0000000..59fc382 --- /dev/null +++ b/application/admin/view/manystore/shop_apply/add.html @@ -0,0 +1,75 @@ +
+ +
+ +
+ + + + + + + +
+
+
+ +
+ + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + +
diff --git a/application/admin/view/manystore/shop_apply/edit.html b/application/admin/view/manystore/shop_apply/edit.html new file mode 100644 index 0000000..2f0ff6f --- /dev/null +++ b/application/admin/view/manystore/shop_apply/edit.html @@ -0,0 +1,76 @@ +
+ +
+ +
+ + + + + + + + +
+
+
+ +
+ + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + +
diff --git a/application/admin/view/manystore/shop_apply/index.html b/application/admin/view/manystore/shop_apply/index.html new file mode 100644 index 0000000..6c22245 --- /dev/null +++ b/application/admin/view/manystore/shop_apply/index.html @@ -0,0 +1,29 @@ +
+ {:build_heading()} + +
+
+
+ +
+ +
+
+
diff --git a/application/api/controller/school/Shop.php b/application/api/controller/school/Shop.php index b1989c6..c15a370 100644 --- a/application/api/controller/school/Shop.php +++ b/application/api/controller/school/Shop.php @@ -3,6 +3,7 @@ namespace app\api\controller\school; use app\common\model\dyqc\ManystoreShop; +use app\common\model\manystore\ShopApply; /** * 机构接口 @@ -61,8 +62,8 @@ class Shop extends Base /** 机构申请 - * @ApiTitle( 机构申请) - * @ApiSummary(机构申请) + * @ApiTitle( 机构申请(废弃)) + * @ApiSummary(机构申请(废弃)) * @ApiRoute(/api/school/shop/shopapply) * @ApiMethod(POST) * @ApiParams(name = "name", type = "string",required=true,description = "机构名称") @@ -161,8 +162,8 @@ class Shop extends Base /** 个人申请 - * @ApiTitle( 个人申请) - * @ApiSummary(个人申请) + * @ApiTitle( 个人申请(废弃)) + * @ApiSummary(个人申请(废弃)) * @ApiRoute(/api/school/shop/userapply) * @ApiMethod(POST) * @ApiParams(name = "name", type = "string",required=true,description = "姓名") @@ -442,4 +443,47 @@ class Shop extends Base } + + + /** 机构申请新版接口 + * @ApiTitle( 机构申请新版接口) + * @ApiSummary(机构申请新版接口) + * @ApiRoute(/api/school/shop/apply) + * @ApiMethod(POST) + * @ApiParams(name = "type", type = "string",required=true,description = "类型:1=个人,2=机构") + * @ApiParams(name = "name", type = "string",required=true,description = "机构名称(机构入驻才需要)") + * @ApiParams(name = "realname", type = "string",required=true,description = "联系人姓名") + * @ApiParams(name = "mobile", type = "string",required=true,description = "联系电话") + * @ApiParams(name = "address", type = "string",required=true,description = "地址") + * @ApiReturn({ + * + *}) + */ + public function apply(){ + $params=[]; + $params["name"] = $this->request->post('name/s',''); + $params["realname"] = $this->request->post('realname/s',''); + $params["mobile"] = $this->request->post('mobile/s',''); + $params["address"] = $this->request->post('address/s',''); + $params["type"] = $this->request->post('type/s',''); + +// if(empty($id)){ +// $this->error(__('缺少必要参数')); +// } + $type = $params["type"]; + $user_id = 0; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + $params["user_id"] = $user_id; + try { + $res = (new ShopApply())->apply($type,$user_id,$params,true,true); + } catch (\Exception $e){ +// Log::log($e->getMessage()); + $this->error($e->getMessage(),['errcode'=>$e->getCode()]); + } + $this->success('获取成功', ['detail' => $res]); + } + + + } \ No newline at end of file diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index f987159..d4a8097 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -208,7 +208,7 @@ class Backend extends Controller $q_fields = []; foreach ($get as $kay=>$getField) { - if (in_array($kay, $fieldLists)) { + if (in_array($kay, $fieldLists) || in_array($kay, $this->qFields)) { $q_fields[$kay] = $getField; } } diff --git a/application/common/controller/ManystoreBase.php b/application/common/controller/ManystoreBase.php index 4ed78b0..0e58567 100644 --- a/application/common/controller/ManystoreBase.php +++ b/application/common/controller/ManystoreBase.php @@ -175,7 +175,7 @@ class ManystoreBase extends Controller $q_fields = []; foreach ($get as $kay=>$getField) { - if (in_array($kay, $fieldLists)) { + if (in_array($kay, $fieldLists) || in_array($kay, $this->qFields)) { $q_fields[$kay] = $getField; } } diff --git a/application/common/model/dyqc/ManystoreShop.php b/application/common/model/dyqc/ManystoreShop.php index 08ccf77..c687ce4 100644 --- a/application/common/model/dyqc/ManystoreShop.php +++ b/application/common/model/dyqc/ManystoreShop.php @@ -5,6 +5,7 @@ namespace app\common\model\dyqc; use app\admin\model\Admin; use app\common\library\Virtual; use app\common\model\BaseModel; +use app\common\model\manystore\ShopApply; use app\common\model\school\Area; use app\common\model\school\classes\activity\Activity; use app\common\model\school\classes\ClassesLib; @@ -894,7 +895,7 @@ public static function getAuthInfo($user_id){ $verification = true; //核销权限 $verification_shop_id = 0; //可核销机构 - + $join_number = self::getJoinNumber(); try{ $verification_shop_id = ClassesLib::checkOptionAuth(0,$user_id,"user"); }catch (\Exception $e){ @@ -907,7 +908,7 @@ public static function getAuthInfo($user_id){ if(!$verification_classes_lib_ids && !$verification_shop_id && !$verification_classes_activity_ids){ $verification = false; } - $verification_auth = compact("verification","verification_shop_id","verification_classes_lib_ids","verification_classes_activity_ids"); + $verification_auth = compact("join_number","verification","verification_shop_id","verification_classes_lib_ids","verification_classes_activity_ids"); @@ -926,14 +927,14 @@ public static function getAuthInfo($user_id){ "logo" ]; $apply_info = null; - if(!$user_id)return compact("verification_auth","check_full_msg","check_full","check_field",'auth_status','shop_id','reason','apply_info',"type"); + if(!$user_id)return compact("join_number","verification_auth","check_full_msg","check_full","check_field",'auth_status','shop_id','reason','apply_info',"type"); //得到申请单 $apply_info = self::where("user_id",$user_id)->where("status","1")->find(); if(!$apply_info)$apply_info = self::where("user_id",$user_id)->find(); //不存在说明未申请,直接返回 if(!$apply_info){ - return compact("verification_auth","check_full_msg","check_full","check_field",'auth_status','shop_id','reason','apply_info',"type"); + return compact("join_number","verification_auth","check_full_msg","check_full","check_field",'auth_status','shop_id','reason','apply_info',"type"); } $type = $apply_info['type']; //从申请单取到申请状态 @@ -952,7 +953,17 @@ public static function getAuthInfo($user_id){ $check_full_msg = $self->checkFullMsg($shop_id); $check_full = $self->checkFull($shop_id); - return compact("verification_auth","check_full_msg","check_full","check_field",'auth_status','shop_id','reason','apply_info',"type"); + + return compact("join_number","verification_auth","check_full_msg","check_full","check_field",'auth_status','shop_id','reason','apply_info',"type"); +} + + + +public static function getJoinNumber($real=false) +{ + $number =self::count(); + if($real) return $number; + return $number + (int) config('site.shop_base_apply_num'); } @@ -1085,6 +1096,16 @@ public static function getAuthInfo($user_id){ $manystore = Manystore::where("shop_id" ,$shop_id)->find(); if($user && $manystore){ + //更新申请表单状态 + $shopApply = ShopApply::where("id",$manystore["shop_apply_id"])->find(); + if($shopApply){ + $shopApply->shop_id = $shop_id; + $shopApply->store_id = $manystore["id"]; + $shopApply->save(); + } + + + //授权认证成功 $result = \app\common\model\manystore\UserAuth::auth(0,$shop["id"],$shop["user_id"],"1",'admin',0); //删除用户所有老师和核销员 diff --git a/application/common/model/manystore/ShopApply.php b/application/common/model/manystore/ShopApply.php new file mode 100644 index 0000000..9cbd4b8 --- /dev/null +++ b/application/common/model/manystore/ShopApply.php @@ -0,0 +1,174 @@ + __('Type 1'), '2' => __('Type 2')]; + } + + + public function getTypeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['type']) ? $data['type'] : ''); + $list = $this->getTypeList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + + public function getCreateTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + + public function getUpdateTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + protected function setCreateTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + protected function setUpdateTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + + public function user() + { + return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + + public function shop() + { + return $this->belongsTo(Shop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + + public function apply($type,$user_id=0,$params,$check=false,$trans=false){ + + if(!in_array($type,['1','2'])) throw new \Exception('类型参数错误'); + + if($check){ + $user = User::get($user_id ?: ($params["user_id"] ?? 0)); + if(!$user)throw new \Exception("用户不存在"); + //已经是机构 + $shop = ManystoreShop::where( 'user_id',$user_id)->find(); + if($shop){ + throw new \Exception("已是机构,请勿重复申请"); + }else{ + //申请认证的时候不能是老师或其他机构的核销员 + $teacher = Teacher::where("user_id" ,$user_id)->find(); + if($teacher) throw new \Exception("您已经是老师,不能申请认证!"); + + $verification = Verification::where("user_id" ,$user_id)->find(); + if($verification) throw new \Exception("您已经是机构核销员,不能申请认证!"); + } + + } + + + switch ($type) { + case '1': //个人 + $rule = [ + 'realname' => 'require', + 'user_id' => 'require', + 'mobile' => 'require', + 'address' => 'require', + ]; + $rule_msg = [ + 'user_id.require' => '请指定提交用户', +// 'name.require' => '机构名称必须填写', + 'realname.require' => '联系人必须填写', + 'mobile.require' => '联系人电话必须是数字', + 'address.require' => '联系地址必须填写', + ]; + break; + case '2': //机构 + + $rule = [ + 'name' => 'require', + 'realname' => 'require', + 'mobile' => 'require', + 'address' => 'require', + 'user_id' => 'require', + ]; + + $rule_msg = [ + 'user_id.require' => '请指定提交用户', + 'name.require' => '机构名称必须填写', + 'realname.require' => '联系人必须填写', + 'mobile.require' => '联系人电话必须是数字', + 'address.require' => '联系地址必须填写', + ]; + + break; + } + self::check($params,$rule,$rule_msg); + + + + +//判断逻辑 + if($trans){ + self::beginTrans(); + } +// $res = false; + try{ + $res = self::create($params); + + if($trans){ + self::commitTrans(); + } + }catch (\Exception $e){ + if($trans){ + self::rollbackTrans(); + } + throw new \Exception($e->getMessage().$e->getFile().$e->getLine()); + } + return $res; + } +} diff --git a/application/database.php b/application/database.php index bb8fc99..f7b0d00 100644 --- a/application/database.php +++ b/application/database.php @@ -18,11 +18,11 @@ return [ // 服务器地址 'hostname' => Env::get('database.hostname', '127.0.0.1'), // 数据库名 - 'database' => Env::get('database.database', 'duoyangqingchunyexiao'), + 'database' => Env::get('database.database', 'duoyangnew'), // 用户名 - 'username' => Env::get('database.username', 'duoyangqingchun'), + 'username' => Env::get('database.username', 'duoyangnew'), // 密码 - 'password' => Env::get('database.password', 'C8YrFHBDwjaxjYbF'), + 'password' => Env::get('database.password', 'hXJ4FfJhXYsBcXte'), // 端口 'hostport' => Env::get('database.hostport', ''), // 连接dsn diff --git a/public/assets/js/backend/manystore/shop_apply.js b/public/assets/js/backend/manystore/shop_apply.js new file mode 100644 index 0000000..63427ec --- /dev/null +++ b/public/assets/js/backend/manystore/shop_apply.js @@ -0,0 +1,127 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'manystore/shop_apply/index' + location.search, + add_url: 'manystore/shop_apply/add', + edit_url: 'manystore/shop_apply/edit', + del_url: 'manystore/shop_apply/del', + multi_url: 'manystore/shop_apply/multi', + generate_url: 'manystore/shop_apply/generate',//生成机构 + import_url: 'manystore/shop_apply/import', + table: 'manystore_shop_apply', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + fixedColumns: true, + fixedRightNumber: 1, + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'user_id', title: __('User_id')}, + {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal}, + {field: 'name', title: __('Name'), operate: 'LIKE'}, + {field: 'realname', title: __('Realname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'mobile', title: __('Mobile'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'shop_id', title: __('Shop_id')}, + {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, + {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, + {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'}, + {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'}, + {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image}, + {field: 'shop.name', title: __('Shop.name'), operate: 'LIKE'}, + {field: 'shop.logo', title: __('Shop.logo'), operate: 'LIKE'}, + // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + + {field: 'operate', title: __('Operate'), table: table , buttons: [ + { + name: 'edit', + text: __('生成机构'), + title: __('生成机构'), + auth:"edit", + classname: 'btn btn-xs btn-danger btn-magic btn-dialog', + icon: 'fa fa-cube', + // dropdown : '更多', + url: generate_url, + callback: function (data) { + + }, + visible: function (row) { + return !row.shop_id; + } + }, + + + + { + name: 'generate', + text: __('查看机构'), + title: __('查看机构'), + auth:"generate", + classname: 'btn btn-xs btn-danger btn-magic btn-dialog', + icon: 'fa fa-cubes', + // dropdown : '更多', + url: list_url, + callback: function (data) { + + }, + visible: function (row) { + return row.shop_id; + } + }, + + ], events: Table.api.events.operate, formatter: Table.api.formatter.operate}, + + + + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + edit: function () { + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + Form.api.bindevent($("form[role=form]")); + } + } + }; + + + + var generate_url = function (row,dom) { + + return 'manystore/index/add?user_id='+row.user_id + + '&type='+row.type + + '&name=' + (row.name || row.realname) + + '&tel='+row.mobile + + '&shop_apply_id='+row.id + + '&address_detail='+row.address + '&legal_entity='+row.realname; + + }; + + var list_url = function (row,dom) { + return 'manystore/index/index?id='+row.store_id; + }; + + return Controller; +});