123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\admin\model\ManagerChange;
- use think\App;
- use think\facade\Db;
- use think\facade\Validate;
- class Manager extends Base
- {
- protected $model=null;
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model=new ManagerChange();
- }
-
- public function create(){
- $param = $this->request->only(["orderCode"=>[],"manager"=>"","managerid"=>"","companyNo"=>"","remark"=>""],"post","trim");
- $valid=Validate::rule([
- "orderCode|订单集合"=>"require|array",
- "manager|项目经理"=>"require|max:255",
- "managerid|项目经理"=>"require|number|gt:0",
- "companyNo|业务公司"=>"require"
- ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $orderinfo= Db::name("sale")->whereIn("orderCode",$param['orderCode'])->where("supplierNo",$param['companyNo'])
- ->column("orderCode,manager,managerid","orderCode");
- if(count($orderinfo)!= count($param['orderCode'])) return error_show(1004,"数据存在业务公司不一致");
- $userCommon = \app\admin\common\User::getIns();
- $supp = $userCommon->handle("getCodeAndName",["code"=>$param['companyNo']]);
- if(!isset($supp['data']) || empty($supp['data'])) return error_show(1004,'业务公司数据未获取到');
- $companyName = $supp['data'][$param['companyNo']]?:"";
- foreach ($orderinfo as $item){
- $data[]=[
- 'apply_id'=>$this->uid,
- 'apply_name'=>$this->uname,
- 'orderCode'=>$item['orderCode'],
- 'old_manager'=>$item['manager'],
- 'old_managerid'=>$item['managerid'],
- 'companyName'=>$companyName,
- 'companyNo'=>$param['companyNo'],
- 'manager'=>$param['manager'],
- 'managerid'=>$param['managerid'],
- 'remark'=>$param['remark'],
- 'status'=>1
- ];
- }
-
- $ad =$this->model->saveAll($data);
- return $ad? app_show(0,"创建成功"): error_show(1004,"创建失败");
- }
-
- public function list(){
- $param = $this->request->only(['orderCode'=>'','oaCode'=>'','companyNo'=>'','apply_name'=>'','status'=>'','manager'=>'','old_manager'=>'','page'=>1,'size'=>15],'post','trim');
- $where=[];
- $param['orderCode']==''?: $where[]=['orderCode','like',"%{$param['orderCode']}%"];
- $param['apply_name']==''?: $where[]=['apply_name','like',"%{$param['apply_name']}%"];
- $param['companyNo']==''?: $where[]=['companyNo','like',"%{$param['companyNo']}%"];
- $param['manager']==''?: $where[]=['manager','like',"%{$param['manager']}%"];
- $param['old_manager']==''?: $where[]=['old_manager','like',"%{$param['old_manager']}%"];
- $param['status']==''?: $where[]=['status','=',$param['status']];
- $list = $this->model->where($where)->order('id','desc')->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
- return app_show(0,'获取成功',['list'=>$list->items(),'count'=>$list->total()]);
- }
-
- public function info(){
- $param = $this->request->only(['id'],'post','trim');
- $info = $this->model->findOrEmpty($param['id']);
- return app_show(0,'获取成功',$info);
- }
-
- public function status(){
- $param = $this->request->only(['id'=>'','status'=>'','remark'=>''],'post','trim');
- $Valid =Validate::rule(['id|申请id'=>'require','status|状态'=>'require|number|in:2,3']);
- if($Valid->check($param)==false) return error_show(1004,$Valid->getError());
- $info = $this->model->findOrEmpty($param['id']);
- if($info->isEmpty())return error_show(1004,'未找到申请单数据');
- if($info->status!=1) return error_show(1004,'申请单数据已审核');
-
- $info->status=$param['status'];
- $info->remark=$param['remark'];
- $this->model->startTrans();
- try{
- $up=$info->save();
- if($up==false)throw new \Exception('申请单审核失败');
- if($param['status']==2){
- $update=["manager"=>$info->manager,"managerid"=>$info->managerid,"updatetime"=>date("Y-m-d H:i:s")];
- Db::name("sale")->where("orderCode",$info->orderCode)->update($update);
- }
- $this->model->commit();
- }catch (\Exception $exception){
- $this->model->rollback();
- return error_show(1004,$exception->getMessage());
- }
- return app_show(0,'申请数据处理完成');
- }
- //批量导入
- public function export(){
- $param = $this->request->only(['list'=>[],'companyNo'=>''],'post','trim');
- $Valid =Validate::rule([
- 'list|申请修改数据'=>'require|array',
- 'companyNo|业务公司'=>'require'
- ]);
- if($Valid->check($param)==false) return error_show(1004,$Valid->getError());
- $valid=Validate::rule([
- 'orderCode|订单集合'=>'require',
- 'manager|项目经理'=>'require|max:255',
- 'managerid|项目经理'=>'require|number|gt:0'
- ]);
- $userCommon = \app\admin\common\User::getIns();
- $supp = $userCommon->handle('getCodeAndName',['code'=>$param['companyNo']]);
- if(!isset($supp['data']) || empty($supp['data'])) return error_show(1004,'业务公司数据未获取到');
- $companyName = $supp['data'][$param['companyNo']]?:'';
- $orderUp=[];
- $changeIn=[];
- $sale=new \app\admin\model\Sale();
- foreach ($param['list'] as $item){
- if($valid->check($item)==false) return error_show(1004,$valid->getError());
- $orderInfo = $sale->where(["orderCode"=>$item['orderCode'],"is_del"=>0])->findOrEmpty();
- if($orderInfo->isEmpty()) return error_show(1004,"{$item['orderCode']} 未找到数据");
- if($orderInfo['supplierNo']!=$param['companyNo'])return error_show(1004,"{$item['orderCode']} 业务公司不一致");
- $orderUp[]=["id"=>$orderInfo['id'],"manager"=>$item['manager'],"managerid"=>$item['managerid'],"updatetime"=>date("Y-m-d H:i:s")];
- $changeIn[]=[
- 'orderCode'=>$item['orderCode'],
- 'apply_id'=>$this->uid,
- 'apply_name'=>$this->uname,
- 'manager'=>$item['manager'],
- 'managerid'=>$item['managerid'],
- 'companyName'=>$companyName,
- 'companyNo'=>$param['companyNo'],
- 'old_manager'=>$orderInfo->manager,
- 'remark'=>'',
- 'status'=>2,
- 'old_managerid'=>$orderInfo->managerid
- ];
- }
-
- $this->model->startTrans();
- try{
- if(empty($orderUp)==false)$sale->saveAll($orderUp);
- if(empty($orderUp)==false)$this->model->saveAll($changeIn);
- $this->model->commit();
- }catch (\Exception $e){
- $this->model->rollback();
- return error_show(1004,$e->getMessage());
- }
- return app_show(0,'申请数据处理完成');
- }
- }
|