DataChange.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use think\App;
  5. use think\facade\Validate;
  6. use think\facade\Db;
  7. class DataChange extends Base
  8. {
  9. protected $model;
  10. public function __construct(App $app) {
  11. parent::__construct($app);
  12. $this->model=new \app\admin\model\DataChange();
  13. }
  14. /**
  15. * @return \think\response\Json|void
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\DbException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. */
  20. public function create(){
  21. $param =$this->request->only(["code"=>'',"type"=>"",'oaCode'=>'',"change"=>"","apply_id"=>"","apply_name"=>""],
  22. "post","trim");
  23. $valid =Validate::rule([
  24. "code|订单编号"=>"require",
  25. "type|订单类型"=>"require|number|in:1,2,3",
  26. "apply_id|申请人"=>"require|number",
  27. "change|修改字段内容"=>"require|array"]);
  28. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  29. if($param['type']==1){
  30. $orderinfo = Db::name("purchease_order")->where(["cgdNo"=>$param['code']])->find();
  31. $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$param['code'],'is_cgd_check'=>1]);
  32. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  33. return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  34. }
  35. }
  36. if($param['type']==2){
  37. $orderinfo = Db::name('sale')->where(['orderCode'=>$param['code']])->find();
  38. $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$param['code'],'is_cgd_check'=>0]);
  39. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  40. return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  41. }
  42. }
  43. if($param['type']==3){
  44. $orderinfo = Db::name('good_zixun')->where(['spuCode'=>$param['code']])->find();
  45. }
  46. $ist =$this->model->where(["code"=>$param['code'],"status"=>1])->findOrEmpty();
  47. if($ist->isEmpty()==false)return error_show(1004,"订单修改存在未完成得流程");
  48. if($orderinfo==false) return error_show(1004,"订单数据未找到");
  49. if($param['type']==1 && $orderinfo['order_source']!=2 )return error_show(1004,'供应商非咨询单订单不可修改');
  50. $array_diff=array_diff($param['change'],$orderinfo);
  51. $order=[];
  52. $userCommon= \app\admin\common\User::getIns();
  53. foreach ($array_diff as $key=>$iten){
  54. $order[$key] = $orderinfo[$key]??"";
  55. if($param['type']==1 && $key=='supplierNo'){
  56. $persion =$userCommon->handle("sInfo",["code"=>$iten]);
  57. if(isset($persion['data'])&& !empty($persion['data'])){
  58. $array_diff['cgder'] =$persion['data']['person']?:"";
  59. $array_diff['cgder_id'] =$persion['data']['personid']?:"";
  60. }
  61. }
  62. }
  63. $before = json_encode($order,JSON_UNESCAPED_UNICODE);
  64. $after = json_encode($array_diff,JSON_UNESCAPED_UNICODE);
  65. $data=[
  66. "code"=>$param['code'],
  67. "type"=>$param['type'],
  68. "before"=>$before,
  69. "after"=>$after,
  70. "oaCode"=>$param['oaCode'],
  71. "apply_id"=>$param['apply_id'],
  72. "apply_name"=>$param['apply_name'],
  73. 'creater_id'=>$this->uid,
  74. 'creater'=>$this->uname,
  75. "status"=>1,
  76. ];
  77. $in =$this->model->save($data);
  78. return $in? app_show(0,"新建成功"):error_show(1004,"新建失败");
  79. }
  80. public function list(){
  81. $param = $this->request->only(["code"=>"","oaCode"=>"","type"=>"","apply_name"=>"","status"=>"","page"=>1,
  82. "size"=>15],"post","trim");
  83. $where=[["source","=",1]];
  84. $param['code']==''?: $where[]=["code","like","%{$param['code']}%"];
  85. $param['apply_name']==''?: $where[]=["apply_name","like","%{$param['apply_name']}%"];
  86. $param['oaCode']==''?: $where[]=["oaCode","like","%{$param['oaCode']}%"];
  87. $param['type']==''?: $where[]=["type","=",$param['type']];
  88. $param['status']==''?: $where[]=["status","=",$param['status']];
  89. $list = $this->model->where($where)->json(["before","after"])->order("id","desc")->paginate(["page"=>$param['page'],
  90. "list_rows"=>$param['size']]);
  91. return app_show(0,"获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  92. }
  93. public function info(){
  94. $param = $this->request->only(['id'],'post','trim');
  95. $info = $this->model->json(['before','after'])->findOrEmpty($param['id']);
  96. return app_show(0,'获取成功',$info);
  97. }
  98. public function status(){
  99. $param = $this->request->only(['id'=>"",'status'=>"",'remark'=>""],'post','trim');
  100. $Valid =Validate::rule(["id|申请id"=>"require","status|状态"=>"require|number|in:2,3"]);
  101. if($Valid->check($param)==false) return error_show(1004,$Valid->getError());
  102. $info = $this->model->findOrEmpty($param['id']);
  103. if($info->isEmpty())return error_show(1004,'未找到申请单数据');
  104. if($info->status!=1) return error_show(1004,'申请单数据已审核');
  105. $info->status=$param['status'];
  106. $info->remark=$param['remark'];
  107. if($info->status==2 && $info->type!=3){
  108. if($info->type==1){
  109. $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$info->code,"is_cgd_check"=>1]);
  110. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  111. return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  112. }
  113. }
  114. if($info->type==2){
  115. $fininfo =GetFin('admin/orderischeck',['token'=>$this->post['token'],'orderCode'=>$info->code,'is_cgd_check'=>0]);
  116. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  117. return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  118. }
  119. }
  120. }
  121. $this->model->startTrans();
  122. try{
  123. $up=$info->save();
  124. if($up==false)throw new \Exception("申请单审核失败");
  125. if($param['status']==2){
  126. $this->model->updateOrder($info);
  127. }
  128. $this->model->commit();
  129. }catch (\Exception $exception){
  130. $this->model->rollback();
  131. return error_show(1004,$exception->getMessage());
  132. }
  133. return app_show(0,"申请数据处理完成");
  134. }
  135. }