BrandAuth.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wugg
  5. * @DateTime : 2024-06-28 16:01
  6. * @Description : 品牌授权
  7. * @Version : 1.0
  8. */
  9. namespace app\admin\controller;
  10. use app\admin\model\BrandBook;
  11. use think\App;
  12. use think\facade\Validate;
  13. class BrandAuth extends Base{
  14. public function __construct(App $app) {
  15. parent::__construct($app);
  16. $this->model=new \app\admin\model\BrandBook();
  17. }
  18. /**
  19. * 添加品牌授权
  20. * @param \think\Request $request
  21. * @return \think\Response|\think\response\Json|void
  22. */
  23. public function create(){
  24. $param = $this->request->param([
  25. 'brand_book',
  26. 'gyscode',
  27. 'brand_id',
  28. 'is_del'=>0,
  29. 'remark',
  30. 'long',
  31. 'status'=>0,
  32. 'starttime'=>"",
  33. 'endtime'=>''],'post','trim');
  34. $valid= Validate::rule([
  35. 'brand_book|授权书图片'=>'max:255',
  36. 'gyscode|供应商编号'=>'require|max:255',
  37. 'brand_id|品牌id'=>'require|number|gt:0|unique:app\admin\model\BrandBook,brand_id^gyscode^is_del',
  38. 'long|授权类型'=>'require|number|in:0,1',
  39. 'status|状态'=>'require|number|in:0,1',
  40. 'starttime|开始日期'=>'require|date|dateFormat:Y-m-d H:i:s',
  41. 'endtime|结束日期'=>'requireIf:long,1|date|dateFormat:Y-m-d H:i:s',
  42. ]);
  43. if($valid->check($param)==false) return error($valid->getError());
  44. $data=[
  45. "brand_book"=>$param['brand_book'],
  46. "gyscode"=>$param['gyscode'],
  47. "gysname"=>\app\user\model\Supplier::where('code',$param['gyscode'])->value('name'),
  48. "brand_id"=>$param['brand_id'],
  49. "remark"=>$param['remark'],
  50. "long"=>$param['long'],
  51. "status"=>$param['status'],
  52. "starttime"=>$param['starttime'],
  53. "endtime"=>$param['long']==0?"":$param['endtime'],
  54. "createrid"=>$this->uid,
  55. "creater"=>$this->uname,
  56. ];
  57. $create=$this->model->create($data);
  58. if($create==false)return error('添加失败');
  59. return success("添加成功");
  60. }
  61. /**
  62. * 品牌授权列表
  63. * @param $param page size gyscode name
  64. * @return \think\Response|\think\response\Json
  65. * @throws \think\db\exception\DbException
  66. */
  67. public function list(){
  68. $param = $this->request->param([
  69. 'page'=>1,
  70. 'size'=>10,
  71. 'gyscode'=>'',
  72. 'name'=>'',
  73. ],'post','trim');
  74. $where=[['is_del','=',0]];
  75. if($param['gyscode']!=''){
  76. $where[]=['gyscode','like','%'.$param['gyscode'].'%'];
  77. }
  78. if($param['name']!=''){
  79. $where[]=['name','like','%'.$param['name'].'%'];
  80. }
  81. $list= $this->model->with(["brandInfo"])->where($where)->paginate(["list_rows"=>$param['size'],
  82. "page"=>$param['page']]);
  83. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  84. }
  85. /**
  86. * 品牌授权详情
  87. * @param $param id
  88. * @return \think\Response|\think\response\Json
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\DbException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. */
  93. public function info(){
  94. $id = $this->request->post('id/d');
  95. $info=$this->model->with(["brandInfo"])->findOrEmpty($id);
  96. if($info->isEmpty()){
  97. return error('未找到对应数据');
  98. }
  99. return success('获取成功',$info);
  100. }
  101. /**
  102. * 品牌授权状态
  103. * @param $param id 主键id status 状态
  104. * @return \think\Response|\think\response\Json
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\DbException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. */
  109. public function status(){
  110. $param = $this->request->param([
  111. 'id',
  112. 'status',
  113. ],'post','intval');
  114. $valid= Validate::rule([
  115. 'id|主键id'=>'require|number|gt:0',
  116. 'status|状态'=>'require|number|in:0,1',
  117. ]);
  118. if($valid->check($param)==false) return error($valid->getError());
  119. $info=$this->model->findOrEmpty($param['id']);
  120. if($info->isEmpty()){
  121. return error('未找到对应数据');
  122. }
  123. $info->status=$param['status'];
  124. $save=$info->save();
  125. if($save==false)return error(BrandBook::$statusCn[$param['status']].'失败');
  126. return success(BrandBook::$statusCn[$param['status']].'成功');
  127. }
  128. /**
  129. * 品牌授权删除
  130. * @param $param id
  131. * @return \think\Response|\think\response\Json
  132. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\DbException
  134. * @throws \think\db\exception\ModelNotFoundException
  135. */
  136. public function delete(){
  137. $id=$this->request->post('id/d');
  138. $info = $this->model->findOrEmpty($id);
  139. if($info->isEmpty()){
  140. return error('未找到对应数据');
  141. }
  142. $info->is_del=1;
  143. $save=$info->save();
  144. if($save==false)return error('删除失败');
  145. return success('删除成功');
  146. }
  147. /**
  148. * 品牌授权编辑
  149. * @param id 主键id
  150. * @param brand_book 授权书图片
  151. * @param gyscode 供应商编号
  152. * @param brand_id 品牌id
  153. * @param is_del 删除状态
  154. * @param remark 备注
  155. * @param long 授权类型
  156. * @param status 状态
  157. * @param starttime 开始日期
  158. * @param endtime 结束日期
  159. * @return \think\Response|\think\response\Json
  160. * @throws \think\db\exception\DataNotFoundException
  161. * @throws \think\db\exception\DbException
  162. * @throws \think\db\exception\ModelNotFoundException
  163. */
  164. public function edit(){
  165. $param = $this->request->param([
  166. 'id',
  167. 'brand_book',
  168. 'gyscode',
  169. 'brand_id',
  170. 'is_del'=>0,
  171. 'remark',
  172. 'long',
  173. 'status',
  174. 'starttime'=>date('Y-m-d H:i:s'),
  175. 'endtime'=>''],'post','trim');
  176. $valid= Validate::rule([
  177. 'id|主键id'=>'require|number|gt:0',
  178. 'brand_book|授权书图片'=>'url',
  179. 'gyscode|供应商编号'=>'require|max:255',
  180. 'brand_id|品牌id'=>'require|number|gt:0|unique:app\admin\model\BrandBook,brand_id^gyscode^is_del',
  181. 'long|授权类型'=>'require|number|in:0,1',
  182. 'status|状态'=>'require|number|in:0,1',
  183. 'starttime|开始日期'=>'require|date|dateFormat:Y-m-d H:i:s',
  184. 'endtime|结束日期'=>'requireIf:long,1|date|dateFormat:Y-m-d H:i:s',
  185. ]);
  186. if($valid->check($param)==false) return error($valid->getError());
  187. $info=$this->model->findOrEmpty($param['id']);
  188. if($info->isEmpty()){
  189. return error('未找到对应数据');
  190. }
  191. $info->brand_book=$param['brand_book'];
  192. $info->gyscode=$param['gyscode'];
  193. $info->gysname=\app\user\model\Supplier::where('code',$param['gyscode'])->value('name');
  194. $info->brand_id=$param['brand_id'];
  195. $info->remark=$param['remark'];
  196. $info->long=$param['long'];
  197. $info->status=$param['status'];
  198. $info->starttime=$param['starttime'];
  199. $info->endtime=$param['long']==0?'':$param['endtime'];
  200. $save=$info->save();
  201. if($save==false)return error('修改失败');
  202. return success('修改成功');
  203. }
  204. /**
  205. * 品牌授权查询
  206. * @param brand_id 品牌id
  207. * @param gyscode 供应商编号
  208. * @param is_del 删除状态
  209. * @return \think\Response|\think\response\Json
  210. * @throws \think\db\exception\DataNotFoundException
  211. * @throws \think\db\exception\DbException
  212. * @throws \think\db\exception\ModelNotFoundException
  213. */
  214. public function query(){
  215. $param =$this->request->param(['brand_id'=>'','gyscode'=>'','is_del'=>0],'post','trim');
  216. $valid = Validate::rule(['brand_id|品牌id'=>'require|number|gt:0','gyscode|供应商编号'=>'require']);
  217. if($valid->check($param)==false) return error($valid->getError());
  218. $where=[["is_del","=",0]];
  219. if($param['brand_id']!=''){
  220. $where[]=["brand_id","=",$param['brand_id']];
  221. }
  222. if($param['gyscode']!=''){
  223. $where[]=["gyscode","=",$param['gyscode']];
  224. }
  225. $info = $this->model->with(["brandInfo"])->where($where)->findOrEmpty();
  226. if($info->isEmpty()){
  227. return error('未找到对应数据');
  228. }
  229. return success('获取成功',$info);
  230. }
  231. }