123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- class Suppler extends BaseController
- {
- public $post = "";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- }
- public function create(){
- $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
- // $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
- // if (!empty($rename)) {
- // return error_show(1002, "公司名称已存在");
- // }
- $code = rand(0000,9999);
- $str = sprintf("%04d",$code);
- $tr="GYS-".date("Ymd")."-".$str;
- $source= isset($this->post['source']) && $this->post['source']!==""? intval($this->post['source']) :"";
- if($source===""){
- return error_show(1002,"供应商来源不能为空");
- }
- $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1005,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"创建人数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $type = isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']) :"";
- if($type===""){
- return error_show(1002,"申请类型不能为空");
- }
- $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? intval($this->post['coop_state']):"";
- if($coop_state===""){
- return error_show(1002,"参数coop_state不能为空");
- }
- $category = isset($this->post['category']) && $this->post['category'] !==""? intval($this->post['category']):"";
- if($category===""){
- return error_show(1002,"参数category不能为空");
- }
- $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? intval($this->post['delivery_way']):"";
- if($delivery_way===""){
- return error_show(1002,"参数delivery_way不能为空");
- }
- $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
- if($level===""){
- return error_show(1002,"参数level不能为空");
- }
- $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? intval($this->post['supplier_type']):"";
- if($supplier_type===""){
- return error_show(1002,"参数supplier_type不能为空");
- }
- $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? intval($this->post['pay_type']):"";
- if($pay_type===""){
- return error_show(1002,"参数pay_type不能为空");
- }
- $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
- if($prove_img==""){
- return error_show(1002,"参数prove_img不能为空");
- }
- // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
- // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
- $nature = isset($this->post['nature']) && $this->post['nature']!==""? intval($this->post['nature']) :"";
- $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
- $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? intval($this->post['ticket_type']) :"";
- $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
- $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
- $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
- $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
- $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
- $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
- $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
- $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
- $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
- $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
- $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
- $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"1";
- $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
- $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
- $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
- if($contactor==""){
- return error_show(1002,"参数contactor不能为空");
- }
- $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
- if($mobile==""){
- return error_show(1002,"参数mobile不能为空");
- }
- $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
- if($position==""){
- return error_show(1002,"参数position不能为空");
- }
- Db::startTrans();
- try{
- $data=[
- "name"=>$name,
- "source"=>$source,
- "coop_state"=>$coop_state,
- "category"=>$category,
- "delivery_way"=>$delivery_way,
- "level"=>$level,
- "supplier_type"=>$supplier_type,
- "pay_type"=>$pay_type,
- "registercode"=>$registercode,
- "capital"=>$capital,
- "product_category"=>$product_category,
- "is_payment"=>$is_payment,
- "notice_mark"=>$notice_mark,
- "agreement"=>$agreement,
- "warehouse"=>$warehouse,
- "pay_day"=>$pay_day,
- "scope"=>$scope,
- "status"=>$status,
- "code"=>$tr,
- "type"=>$type,
- // "area"=>$area,
- // "city"=>$city,
- "nature"=>$nature,
- "legaler"=>$legaler,
- "addr"=>$addr,
- "is_del"=>0,
- "ticket_type"=>$ticket_type,
- "addtime"=>date('Y-m-d H:i:s'),
- "updatetime"=>date("Y-m-d H:i:s"),
- "is_platform"=>$is_platform,
- "prove_img"=>$prove_img,
- "creater"=>$creater,
- "createrid"=>$createrid,
- "registertime"=>date('Y-m-d H:i:s')
- ];
- if($supplier_img==""){
- if($registercode==""){
- return error_show(1002,"参数registercode不能为空");
- }
- if($name==""){
- return error_show(1002,"数据标题不能为空");
- }
- if($nature===""){
- return error_show(1002,"参数nature不能为空");
- }
- if($legaler==""){
- return error_show(1002,"参数legaler不能为空");
- }
- if($registertime==""){
- return error_show(1002,"参数registertime不能为空");
- }
- if($addr==""){
- return error_show(1002,"参数addr不能为空");
- }
- if($scope==""){
- return error_show(1002,"参数scope不能为空");
- }
- $data['registertime']=$registertime;
- }
- $join = Db::name('supplier')->insert($data,true);
- if($join>0){
- $temp = [];
- $temp['code']=$code;
- $temp['contactor'] =$contactor;
- $temp['mobile'] = $mobile;
- $temp['position'] = $position;
- $temp['email'] ="";
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $vp = Db::name('supplier_contact')->insert($temp);
- if ($vp == "") {
- Db::rollback();
- return error_show(1002, "添加失败");
- }
- Db::commit();
- return error_show(0,"添加成功") ;
- }else{
- Db::rollback();
- return error_show(1002,"添加失败");
- }
- }catch (\Exception $e) {
- Db::rollback();
- return error_show(1003, $e->getMessage());
- }
- }
- public function list(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
- $where =[['a.is_del',"=",0]];
- $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
- if($name !==""){
- $where[]=["a.name","like","%$name%"];
- }
- $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
- if($creater !==""){
- $where[] = ["a.creater","like","%$creater%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
- if($status!==""){
- $where[]= ["a.status","=",$status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['a.addtime',">=",$start];
- }
- // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- // if($end !=""){
- // $where[]=['a.addtime',"<=",$end];
- // }
- $contactor = isset($this->post['contactor']) && $this->post['contactor'] !==""? trim($this->post['contactor']):"";
- if($contactor !=""){
- $where[]=["b.contactor","like","%$contactor%"];
- }
- $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):"";
- if($mobile !=""){
- $where[] = ['b.mobile',"like","%$mobile%"];
- }
- $count = Db::name('supplier')->alias("a")
- ->join("supplier_contact b","b.code=a.code","left")
- ->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('supplier')->alias('a')
- ->join("supplier_contact b","b.code=a.code","left")
- ->where($where)->page($page,$size)->order("a.addtime desc")
- ->field("a.*,b.contactor,b.mobile")->select();
- return app_show("0","获取成功",['list'=>$list,'count'=>$count]);
- }
- public function edit(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info = Db::name("supplier")->where(['id'=>$id,'is_del'=>0])->find();
- if($info==""){
- return error_show(1002,"未找到数据");
- }
- $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
- if($source==""){
- return error_show(1002,"供应商来源不能为空");
- }
- $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
- if($type==""){
- return error_show(1002,"申请类型不能为空");
- }
- $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):"";
- if($coop_state==""){
- return error_show(1002,"参数coop_state不能为空");
- }
- $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):"";
- if($category==""){
- return error_show(1002,"参数category不能为空");
- }
- $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):"";
- if($delivery_way==""){
- return error_show(1002,"参数delivery_way不能为空");
- }
- $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
- if($level==""){
- return error_show(1002,"参数level不能为空");
- }
- $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):"";
- if($supplier_type==""){
- return error_show(1002,"参数supplier_type不能为空");
- }
- $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):"";
- if($pay_type==""){
- return error_show(1002,"参数pay_type不能为空");
- }
- $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
- if($prove_img==""){
- return error_show(1002,"参数prove_img不能为空");
- }
- $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
- $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
- $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
- $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
- $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
- $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
- $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
- $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
- $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
- $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
- $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
- $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
- $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
- $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
- $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
- $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
- $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
- $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
- $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
- if($contactor==""){
- return error_show(1002,"参数contactor不能为空");
- }
- $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
- if($mobile==""){
- return error_show(1002,"参数mobile不能为空");
- }
- $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
- if($position==""){
- return error_show(1002,"参数position不能为空");
- }
- try{
- $data=[
- "id"=>$id,
- "source"=>$source,
- "coop_state"=>$coop_state,
- "category"=>$category,
- "delivery_way"=>$delivery_way,
- "level"=>$level,
- "supplier_type"=>$supplier_type,
- "pay_type"=>$pay_type,
- "registercode"=>$registercode,
- "capital"=>$capital,
- "product_category"=>$product_category,
- "is_payment"=>$is_payment,
- "notice_mark"=>$notice_mark,
- "agreement"=>$agreement,
- "warehouse"=>$warehouse,
- "pay_day"=>$pay_day,
- "scope"=>$scope,
- "status"=>$status,
- "type"=>$type,
- "nature"=>$nature,
- "legaler"=>$legaler,
- "addr"=>$addr,
- "is_del"=>0,
- "ticket_type"=>$ticket_type,
- "updatetime"=>date("Y-m-d H:i:s"),
- "is_platform"=>$is_platform,
- "prove_img"=>$prove_img,
- "registertime"=>date("Y-m-d H:i:s"),
- ];
- if($supplier_img==""){
- if($registercode==""){
- return error_show(1002,"参数registercode不能为空");
- }
- if($name==""){
- return error_show(1002,"数据标题不能为空");
- }
- if($nature==""){
- return error_show(1002,"参数nature不能为空");
- }
- if($legaler==""){
- return error_show(1002,"参数legaler不能为空");
- }
- if($registertime==""){
- return error_show(1002,"参数registertime不能为空");
- }
- $data['registertime']=$registertime;
- }
- $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
- if($join){
- $item = Db::name('supplier_contact')->where(['code'=>$join['code']])->find();
- $temp = [];
- isset($item['id']) && $item['id'] !== "" ? $temp['id'] = $item['id'] : '';
- $temp['code'] = $info['code'];
- $temp['contactor'] = $contactor;
- $temp['mobile'] = $mobile;
- $temp['position'] = $position;
- $temp['email'] ="";
- $temp['contactor'] ="";
- $temp['is_del'] = 0;
- isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $vp = Db::name('supplier_contact')->save($temp);
- if ($vp == "") {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- Db::commit();
- return error_show(0,"编辑成功") ;
- }else{
- Db::rollback();
- return error_show(1002,"编辑失败");
- }
- }catch (\Exception $e) {
- Db::rollback();
- return error_show(1003, $e->getMessage());
- }
- }
- public function info(){
- $id = isset($this->post['id'])&& $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id ==""){
- return error_show(1002,"参数id不能为空");
- }
- $info = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
- if($info==""){
- return error_show(1002,"未找到数据");
- }
- return app_show(0,"获取成功",$info);
- }
- public function del(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
- if($sup==false){
- return error_show(1002,"供应商信息不存在");
- }
- $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- if($supp){
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- public function status(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
- if(!$info){
- return error_show(1002,"未找到对应数据");
- }
- $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
- if($status===""){
- return error_show(1002,"参数status不能为空");
- }
- if(!in_array($status,[0,1])){
- return error_show(1002,"参数status无效");
- }
- $info['status']=$status;
- $info['updatetime']=date("Y-m-d H:i:s");
- $msg = $status==1?"启用":"禁用";
- $update = Db::name("supplier")->save($info);
- return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
- }
- }
|