TagGood.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\CgdInfo;use app\admin\model\OrderTag;
  4. use app\admin\model\Pay;
  5. use app\admin\model\QrdInfo;
  6. use app\admin\model\TagLog;
  7. use think\App;
  8. use think\facade\Db;use think\facade\Validate;
  9. class TagGood extends Base{
  10. // public $novalidate=['*'];
  11. public function __construct(App $app) {parent::__construct($app);}
  12. //新建标签
  13. public function create(){
  14. $post = $this->post;
  15. $type = isset($post['type'])&& $post['type']!="" ? intval($post['type']) :"";
  16. if($type==''){
  17. return error_show(1004,"参数 type 不能未空");
  18. }
  19. if($post['relaComNo']!=""){
  20. $companyNo = isset($post['relaComNo'])&& $post['relaComNo']!="" ? trim($post['relaComNo']) :"";
  21. }else{
  22. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  23. }
  24. if($companyNo==''){
  25. return error_show(1004,"参数 companyNo 不能未空");
  26. }
  27. $tagName =isset($post['tag_name'])&&$post['tag_name']!='' ? trim($post['tag_name']):"";
  28. if($tagName==''){
  29. return error_show(1004,"参数 tag_name 不能未空");
  30. }
  31. $isT =Db::name("order_tag")->where(["type"=>$type,"companyNo"=>$companyNo,"tag_name"=>$tagName,"is_del"=>0])
  32. ->findOrEmpty();
  33. if(!empty($isT)){
  34. return error_show(1004,"标签名称已存在");
  35. }
  36. $tagData=[
  37. "type"=>$type,
  38. "tag_name"=>$tagName,
  39. "status"=>1,
  40. "companyNo"=>$companyNo,
  41. "apply_id"=>$this->uid,
  42. "apply_name"=>$this->uname,
  43. "addtime"=>date("Y-m-d H:i:s"),
  44. "updatetime"=>date("Y-m-d H:i:s")
  45. ];
  46. $ins=Db::name("order_tag")->insert($tagData);
  47. return $ins?app_show(0,"标签新建成功"): error_show(1004,"标签新建失败");
  48. }
  49. //标签列表翻页
  50. public function list(){
  51. $page = isset($this->post['page'])&&$this->post['page']!=''?intval($this->post['page']):1;
  52. $size = isset($this->post['size'])&&$this->post['size']!=''?intval($this->post['size']):15;
  53. $type = isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):'';
  54. $status = isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):'';
  55. if(isset($this->post['relaComNo']) && $this->post['relaComNo']!=""){
  56. $companyNo = isset($this->post['relaComNo'])&& $this->post['relaComNo']!="" ? trim($this->post['relaComNo']) :"";
  57. }else{
  58. $companyNo = isset($this->post['companyNo'])&& $this->post['companyNo']!="" ? trim($this->post['companyNo']) :"";
  59. }
  60. $condition =[["is_del","=",0]];
  61. $roleid = $this->roleid;
  62. $check = checkRole($roleid,'101');
  63. if($check){
  64. $condition[]=["apply_id","=",$this->uid];
  65. }
  66. if($type!=''){
  67. $condition[]=["type","=",$type];
  68. }
  69. if($status!==''){
  70. $condition[]=["status","=",$status];
  71. }
  72. $tagName =isset($this->post['tag_name'])&&$this->post['tag_name']!='' ? trim($this->post['tag_name']):"";
  73. if($tagName!=''){
  74. $condition[]=["tag_name","like","%$tagName%"];
  75. }
  76. if($companyNo!=''){
  77. $condition[]=["companyNo","=",$companyNo];
  78. }
  79. $count =Db::name("order_tag")->where($condition)->count();
  80. $total=ceil($count/$size);
  81. $page = $page>=$total ? intval($total):$page;
  82. $list =Db::name("order_tag")->where($condition)->page($page,$size)->order("addtime desc")->select()->toArray();
  83. $comNo=array_column($list,"companyNo");
  84. $ComArr=Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$comNo])->column("name","code");
  85. foreach ($list as &$item){
  86. $item['companyName']=$ComArr[$item['companyNo']]??"";
  87. }
  88. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  89. }
  90. //根据条件筛选合适的标签数据
  91. public function query(){
  92. $type = isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):'';
  93. $condition =[["is_del","=",0]];
  94. if($type!=''){
  95. $condition[]=["type","=",$type];
  96. }
  97. if($this->post['relaComNo']!=""){
  98. $companyNo = isset($this->post['relaComNo'])&& $this->post['relaComNo']!="" ? trim($this->post['relaComNo']) :"";
  99. }else{
  100. $companyNo = isset($this->post['companyNo'])&& $this->post['companyNo']!="" ? trim($this->post['companyNo']) :"";
  101. }
  102. if($companyNo!=''){
  103. $condition[]=["companyNo","=",$companyNo];
  104. }
  105. $tagName =isset($this->post['tag_name'])&&$this->post['tag_name']!='' ? trim($this->post['tag_name']):"";
  106. if($tagName!=''){
  107. $condition[]=["tag_name","like","%$tagName%"];
  108. }
  109. $status = isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):'';
  110. if($status!==''){
  111. $condition[]=["status","=",$status];
  112. }
  113. $list =Db::name("order_tag")->where($condition)->order("addtime desc")->select()->toArray();
  114. return app_show(0,"获取成功",$list);
  115. }
  116. //启禁用状态
  117. public function status(){
  118. $id =isset($this->post['id'])&&$this->post['id']!=''?intval($this->post['id']):'';
  119. if($id==''){
  120. return error_show(1004,"参数 id 不能为空");
  121. }
  122. $taginfo =Db::name("order_tag")->find(["id"=>$id]);
  123. if($taginfo==false){
  124. return error_show(1004,"标签数据不存在");
  125. }
  126. $status=isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):'';
  127. if($status===''){
  128. return error_show(1004,"参数 status 不能为空");
  129. }
  130. $update =["status"=>$status,"updatetime"=>date("Y-m-d H:i:s")];
  131. $up =Db::name("order_tag")->where($taginfo)->update($update);
  132. return $up?app_show(0,"标签更新成功"): error_show(1004,"标签更新失败");
  133. }
  134. //编辑标签名称类型数据
  135. public function save(){
  136. $id =isset($this->post['id'])&&$this->post['id']!=''?intval($this->post['id']):'';
  137. if($id==''){
  138. return error_show(1004,"参数 id 不能为空");
  139. }
  140. $taginfo =Db::name("order_tag")->where(["id"=>$id,"is_del"=>0])->find();
  141. if($taginfo==false){
  142. return error_show(1004,"标签数据不存在");
  143. }
  144. $tagName=isset($this->post['tag_name'])&&$this->post['tag_name']!=''?trim($this->post['tag_name']):'';
  145. if($tagName===''){
  146. return error_show(1004,"参数 tag_name 不能为空");
  147. }
  148. $type=isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):'';
  149. if($type==''){
  150. return error_show(1004,"参数 type 不能为空");
  151. }
  152. $tag =Db::name("order_tag")->where([['tag_name',"=",$tagName],['companyNo',"=",$taginfo['companyNo']],
  153. ['type',"=",$type], ["id","<>",$id],["is_del","=",0]])->find();
  154. if($tag!=false){
  155. return error_show(1004,"标签名称已存在");
  156. }
  157. $update =["type"=>$type,"tag_name"=>$tagName,"updatetime"=>date("Y-m-d H:i:s")];
  158. $up =Db::name("order_tag")->where($taginfo)->update($update);
  159. return $up?app_show(0,"标签更新成功"): error_show(1004,"标签更新失败");
  160. }
  161. //删除标签
  162. public function delete(){
  163. $id =isset($this->post['id'])&&$this->post['id']!=''?intval($this->post['id']):'';
  164. if($id==''){
  165. return error_show(1004,"参数 id 不能为空");
  166. }
  167. $taginfo =Db::name("order_tag")->find(["id"=>$id]);
  168. if($taginfo==false){
  169. return error_show(1004,"标签数据不存在");
  170. }
  171. $update=["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")];
  172. $up =Db::name("order_tag")->where($taginfo)->update($update);
  173. return $up?app_show(0,"标签删除成功"): error_show(1004,"标签删除失败");
  174. }
  175. //单号添加标签
  176. public function AddTag(){
  177. $tagid =isset($this->post["tag_id"]) && $this->post["tag_id"]!=""?intval($this->post["tag_id"]) :"";
  178. if($tagid==""){
  179. return error_show(1004,"参数 tag_id 不能为空");
  180. }
  181. $taginfo =Db::name("order_tag")->where(["id"=>$tagid,"is_del"=>0])->find();
  182. if($taginfo==false){
  183. return error_show(1005,"标签数据不存在");
  184. }
  185. if($taginfo['status']==0){
  186. return error_show(1005,"标签已禁用");
  187. }
  188. $code =isset($this->post['code']) &&$this->post["code"]!="" ? trim($this->post["code"]):"";
  189. if($code==''){
  190. return error_show(1004,"参数 code 不能为空");
  191. }
  192. // $taglog =TagLog::where(["tag_id"=>$tagid,"code"=>$code,"status"=>1])->findOrEmpty();
  193. $total_fee =isset($this->post['total_fee']) &&$this->post["total_fee"]!=="" ? floatval($this->post["total_fee"]):"";
  194. if($total_fee==''){
  195. return error_show(1004,"参数 total_fee 不能为空");
  196. }
  197. $tagimg=isset($this->post["tag_img"]) && $this->post["tag_img"]!=""?$this->post["tag_img"]:"";
  198. $tag_remark=isset($this->post["tag_remark"]) && $this->post["tag_remark"]!=""?$this->post["tag_remark"]:"";
  199. Db::startTrans();
  200. try{
  201. if($taginfo['type']==1 || $taginfo['type']==2){
  202. $this->payTag($taginfo['type'],$code,$total_fee);
  203. }
  204. if($taginfo['type']==3|| $taginfo['type']==4){
  205. $this->qrdTag($taginfo['type'],$code,$total_fee);
  206. }
  207. if($taginfo['type']==5|| $taginfo['type']==6){
  208. $this->cgdTag($taginfo['type'],$code,$total_fee);
  209. }
  210. $tagdata=[
  211. "code"=>$code,
  212. "tag_id"=>$tagid,
  213. "creater"=>$this->uname,
  214. "createrid"=>$this->uid,
  215. "tag_fee"=>$total_fee,
  216. "tag_img"=>$tagimg,
  217. "tag_remark"=>$tag_remark,
  218. "status"=>1,
  219. "addtime"=>date("Y-m-d H:i:s"),
  220. "updatetime"=>date("Y-m-d H:i:s")
  221. ];
  222. $in =Db::name("tag_log")->insert($tagdata);
  223. if($in==false) throw new \Exception("标签日志新建失败");
  224. Db::commit();
  225. return app_show(0,"标签添加成功");
  226. }catch (\Exception $e){
  227. Db::rollback();
  228. return error_show(1004,$e->getMessage());
  229. }
  230. }
  231. //标签废弃
  232. public function checkTag(){
  233. $param= $this->request->post(["logid"=>''],"post","trim");
  234. $loginfo = TagLog::where("id",$param['logid'])->findOrEmpty();
  235. if($loginfo->isEmpty())$this->error('未找到标签关联数据');
  236. $tag = OrderTag::where("id",$loginfo->tag_id)->findOrEmpty();
  237. if($tag->isEmpty())$this->error('未找到标签信息数据');
  238. TagLog::startTrans();
  239. $message="";
  240. try{
  241. if($tag['type']==1 || $tag['type']==2){
  242. $message="对账单{$loginfo->code}{$tag->tag_name}";
  243. $this->payReTag($tag['type'],$loginfo->code,$loginfo->tag_fee);
  244. }
  245. if($tag['type']==3|| $tag['type']==4){
  246. $message="销售单{$loginfo->code}{$tag->tag_name}";
  247. $this->qrdReTag($tag['type'],$loginfo->code,$loginfo->tag_fee);
  248. }
  249. if($loginfo['type']==5|| $loginfo['type']==6){
  250. $message="采购单{$loginfo->code}{$loginfo->tag_name}";
  251. $this->cgdReTag($loginfo['type'],$loginfo->code);
  252. }
  253. $loginfo->status=0;
  254. $loginfo->id=null;
  255. TagLog::create($loginfo->toArray());
  256. }catch (\Exception $exception){
  257. TagLog::rollback();
  258. $this->error($exception->getMessage());
  259. }
  260. TagLog::commit();
  261. $this->success("{$message}数据标签解除");
  262. }
  263. //解除标签
  264. public function returnTag(){
  265. $param= $this->request->post(['orderCode'=>'',"type"=>""],'post','trim');
  266. $valid =Validate::rule(["orderCode|订单编号"=>"require","type|标签类型"=>"require|number|in:1,2,3,4,5,6"]);
  267. if($valid->check($param)==false)$this->error($valid->getError());
  268. $loginfo = TagLog::withJoin(["tagInfo"])->where(['code'=>$param['orderCode'],"tag_log.status"=>[1,2],
  269. 'tagInfo.type'=>$param['type']])->order("tag_log.id","desc")->findOrEmpty();
  270. if($loginfo->isEmpty())$this->error('未找到标签关联数据');
  271. TagLog::startTrans();
  272. $message='';
  273. try{
  274. if($loginfo['type']==1 || $loginfo['type']==2){
  275. $message="对账单{$loginfo->code}{$loginfo->tag_name}";
  276. $fee= $this->payReTag($loginfo['type'],$loginfo->code);
  277. }
  278. if($loginfo['type']==3|| $loginfo['type']==4){
  279. $message="销售单{$loginfo->code}{$loginfo->tag_name}";
  280. $fee= $this->qrdReTag($loginfo['type'],$loginfo->code);
  281. }
  282. if($loginfo['type']==5|| $loginfo['type']==6){
  283. $message="采购单{$loginfo->code}{$loginfo->tag_name}";
  284. $fee= $this->cgdReTag($loginfo['type'],$loginfo->code);
  285. }
  286. $loginfo['status']=0;
  287. $loginfo['tag_fee']=$fee;
  288. unset($loginfo['addtime'],$loginfo['updatetime']);
  289. $loginfo->id=null;
  290. $loginfo->apply_id=$this->uid;
  291. $loginfo->apply_name=$this->uname;
  292. TagLog::create($loginfo->toArray());
  293. }catch (\Exception $exception){
  294. TagLog::rollback();
  295. $this->error($exception->getMessage());
  296. }
  297. TagLog::commit();
  298. $this->success("{$message}数据标签解除");
  299. }
  300. /**
  301. * @param $tagId 标签类型 1 付款2回票
  302. * @param $code 对账单编号
  303. * @param $total_fee 标签金额
  304. * @return \think\response\Json|void
  305. * @throws \think\db\exception\DbException
  306. */
  307. private function payTag($tagId,$code,$total_fee){
  308. $pay=Db::name("pay")->where(["payNo"=>$code,"is_del"=>0])->findOrEmpty();
  309. if(empty($pay)){
  310. throw new \Exception('未找到对账单数据');
  311. }
  312. $update=["updatetime"=>date("Y-m-d H:i:s")];
  313. if($tagId==1){
  314. if($pay['wpay_fee']+$pay['pay_tag_fee']<$total_fee){
  315. throw new \Exception('对账单未付金额不足');
  316. }
  317. $update['wpay_fee']=$pay['wpay_fee']+$pay['pay_tag_fee']-$total_fee;
  318. $status = $update['wpay_fee']==0 &&$pay['pay_fee']==0 ? 3:($pay['apay_fee']==0?1:2);
  319. $update['pay_tag_fee'] =$pay['pay_tag_fee']+ $total_fee;
  320. $update['pay_status'] = $status;
  321. $update['pay_tag'] = 1;
  322. }
  323. if($tagId==2){
  324. if($pay['winv_fee']+$pay['inv_tag_fee']<$total_fee){
  325. throw new \Exception('对账单未开票金额不足');
  326. }
  327. $update['winv_fee']=$pay['winv_fee']+$pay['inv_tag_fee']-$total_fee;
  328. $status = $update['winv_fee']==0 &&$pay['inv_fee']==0 ? 3:($pay['ainv_fee']==0?1:2);
  329. $update['inv_tag_fee'] =$pay['inv_tag_fee']+ $total_fee;
  330. $update['inv_status'] = $status;
  331. $update['inv_tag'] = 1;
  332. }
  333. $resulr= Db::name("pay")->where($pay)->update($update);
  334. if($resulr==false) throw new \Exception('对账单更新失败');
  335. }
  336. /**解除标签
  337. * @param $tagId 标签类型 1 付款2回票
  338. * @param $code 对账单编号
  339. * @param $total_fee 标签金额
  340. * @return \think\response\Json|void
  341. * @throws \think\db\exception\DbException
  342. */
  343. private function payReTag($tagId,$code){
  344. $pay=Pay::where(['payNo'=>$code,'is_del'=>0])->findOrEmpty();
  345. if($pay->isEmpty())throw new \Exception("未找到对账单数据");
  346. $fee=0;
  347. if($tagId==1){
  348. if($pay['pay_tag_fee']<0)throw new \Exception('对账单付款标签金额不足');
  349. $fee=$pay->pay_tag_fee;
  350. $pay->wpay_fee=$pay->wpay_fee+$pay->pay_tag_fee;
  351. $pay->pay_tag_fee=0;
  352. $pay->pay_status = $pay->wpay_fee==0 && $pay->pay_fee==0?3:($pay->apay_fee==0?1:2);
  353. $pay->pay_tag=0;
  354. }
  355. if($tagId==2){
  356. if($pay['inv_tag_fee']<0)throw new \Exception('对账单回票标签金额不足');
  357. $fee=$pay->inv_tag_fee;
  358. $pay->winv_fee=$pay->winv_fee+$pay->inv_tag_fee;
  359. $pay->inv_tag_fee=0;
  360. $pay->inv_status = $pay->winv_fee==0 && $pay->inv_fee==0?3:($pay->ainv_fee==0?1:2);
  361. $pay->inv_tag=0;
  362. }
  363. $resulr= $pay->save();
  364. if($resulr==false)throw new \Exception("对账单更新失败");
  365. return $fee;
  366. }
  367. /**
  368. * @param $tagId 标签类型 3 回款4开票
  369. * @param $code 销售单编号
  370. * @param $total_fee 标签金额
  371. * @return \think\response\Json|void
  372. * @throws \think\db\exception\DbException
  373. */
  374. private function qrdTag($tagId,$code,$total_fee){
  375. $qrd=Db::name("qrd_info")->where(["sequenceNo"=>$code,"is_del"=>0])->findOrEmpty();
  376. if(empty($qrd)){
  377. throw new \Exception('未找到销售单数据');
  378. }
  379. $update=["updatetime"=>date("Y-m-d H:i:s")];
  380. if($tagId==3){
  381. if($qrd['wpay_fee']+$qrd['pay_tag_fee']<$total_fee){
  382. throw new \Exception('销售单未付金额不足');
  383. }
  384. $update['wpay_fee']=$qrd['wpay_fee']+$qrd['pay_tag_fee']-$total_fee;
  385. $status = $update['wpay_fee']==0 &&$qrd['pay_fee']==0 ? 3:($qrd['apay_fee']==0?1:2);
  386. $update['pay_tag_fee'] =$qrd['pay_tag_fee']+ $total_fee;
  387. $update['pay_status'] = $status;
  388. $update['pay_tag'] = 1;
  389. }
  390. if($tagId==4){
  391. if($qrd['winv_fee']+$qrd['inv_tag_fee']<$total_fee){
  392. throw new \Exception('销售单未开票金额不足');
  393. }
  394. $update['winv_fee']=$qrd['winv_fee']+$qrd['inv_tag_fee']-$total_fee;
  395. $status = $update['winv_fee']==0 &&$qrd['inv_fee']==0 ? 3:($qrd['ainv_fee']==0?1:2);
  396. $update['inv_tag_fee'] = $qrd['inv_tag_fee']+$total_fee;
  397. $update['inv_status'] = $status;
  398. $update['inv_tag'] = 1;
  399. }
  400. $resulr= Db::name("qrd_info")->where($qrd)->update($update);
  401. if($resulr==false) throw new \Exception('标签添加失败');
  402. }
  403. /** 解除标签销售单
  404. * @param $tagId 标签类型 3 回款4开票
  405. * @param $code 销售单编号
  406. * @param $total_fee 标签金额
  407. * @return \think\response\Json|void
  408. * @throws \think\db\exception\DbException
  409. */
  410. private function qrdReTag($tagId,$code){
  411. $qrd=QrdInfo::where(['sequenceNo'=>$code,'is_del'=>0])->findOrEmpty();
  412. if($qrd->isEmpty())throw new \Exception('未找到销售单数据');
  413. $fee =0 ;
  414. if($tagId==3){
  415. if($qrd->pay_tag_fee<0)throw new \Exception('销售单回款标签金额不足');
  416. $fee =$qrd->pay_tag_fee ;
  417. $qrd->wpay_fee=$qrd->wpay_fee+$qrd->pay_tag_fee;
  418. $qrd->pay_tag_fee=0;
  419. $qrd->pay_status = $qrd->wpay_fee==0 && $qrd->pay_fee==0?3:($qrd->apay_fee==0?1:2);
  420. $qrd->pay_tag=0;
  421. }
  422. if($tagId==4){
  423. if($qrd->inv_tag_fee<0)throw new \Exception('销售单开票标签金额不足');
  424. $fee =$qrd->inv_tag_fee ;
  425. $qrd->winv_fee=$qrd->winv_fee+$qrd->inv_tag_fee;
  426. $qrd->inv_tag_fee=0;
  427. $qrd->inv_status = $qrd->winv_fee==0 && $qrd->inv_fee==0?3:($qrd->ainv_fee==0?1:2);
  428. $qrd->inv_tag=0;
  429. }
  430. $resulr= $qrd->save();
  431. if($resulr==false)throw new \Exception('销售单更新失败');
  432. return $fee;
  433. }
  434. /**
  435. * @param $tagId 标签类型 3 回款4开票
  436. * @param $code 销售单编号
  437. * @param $total_fee 标签金额
  438. * @return \think\response\Json|void
  439. * @throws \think\db\exception\DbException
  440. */
  441. private function cgdTag($tagId,$code,$total_fee){
  442. $qrd=Db::name('cgd_info')->where(['sequenceNo'=>$code,'is_del'=>0])->findOrEmpty();
  443. if(empty($qrd)){
  444. throw new \Exception('未找到采购单数据');
  445. }
  446. $update=['updatetime'=>date('Y-m-d H:i:s')];
  447. if($tagId==5){
  448. if($qrd['wpay_fee']+$qrd['pay_tag_fee']<$total_fee){
  449. throw new \Exception('采购单未付金额不足');
  450. }
  451. $update['wpay_fee']=$qrd['wpay_fee']+$qrd['pay_tag_fee']-$total_fee;
  452. $status = $update['wpay_fee']==0 ? 3:($qrd['apay_fee']==0?1:2);
  453. $update['pay_tag_fee'] =$qrd['pay_tag_fee']+ $total_fee;
  454. $update['pay_status'] = $status;
  455. $update['pay_tag'] = 1;
  456. }
  457. if($tagId==6){
  458. if($qrd['winv_fee']+$qrd['inv_tag_fee']<$total_fee){
  459. throw new \Exception('采购单未开票金额不足');
  460. }
  461. $update['winv_fee']=$qrd['winv_fee']+$qrd['inv_tag_fee']-$total_fee;
  462. $status = $update['winv_fee']==0 ? 3:($qrd['ainv_fee']==0?1:2);
  463. $update['inv_tag_fee'] = $qrd['inv_tag_fee']+$total_fee;
  464. $update['inv_status'] = $status;
  465. $update['inv_tag'] = 1;
  466. }
  467. $resulr= Db::name('cgd_info')->where($qrd)->update($update);
  468. if($resulr==false) throw new \Exception('标签添加失败');
  469. }
  470. /** 解除标签销售单
  471. * @param $tagId 标签类型 3 回款4开票
  472. * @param $code 销售单编号
  473. * @param $total_fee 标签金额
  474. * @return \think\response\Json|void
  475. * @throws \think\db\exception\DbException
  476. */
  477. private function cgdReTag($tagId,$code){
  478. $qrd=CgdInfo::where(['sequenceNo'=>$code,'is_del'=>0])->findOrEmpty();
  479. if($qrd->isEmpty())throw new \Exception('未找到采购单数据');
  480. $fee =0 ;
  481. if($tagId==5){
  482. if($qrd->pay_tag_fee<0)throw new \Exception('采购单回款标签金额不足');
  483. $fee =$qrd->pay_tag_fee ;
  484. $qrd->wpay_fee=$qrd->wpay_fee+$qrd->pay_tag_fee;
  485. $qrd->pay_tag_fee=0;
  486. $qrd->pay_status = $qrd->wpay_fee==0?3:($qrd->apay_fee==0?1:2);
  487. $qrd->pay_tag=0;
  488. }
  489. if($tagId==6){
  490. if($qrd->inv_tag_fee<0)throw new \Exception('采购单开票标签金额不足');
  491. $fee =$qrd->inv_tag_fee ;
  492. $qrd->winv_fee=$qrd->winv_fee+$qrd->inv_tag_fee;
  493. $qrd->inv_tag_fee=0;
  494. $qrd->inv_status = $qrd->winv_fee==0?3:($qrd->ainv_fee==0?1:2);
  495. $qrd->inv_tag=0;
  496. }
  497. $resulr= $qrd->save();
  498. if($resulr==false)throw new \Exception('采购单更新失败');
  499. return $fee;
  500. }
  501. public function logList(){
  502. $param = $this->request->param(["betweenTime"=>[],"customerNo"=>"","supplierNo"=>"",'companyNo'=>'',
  503. "type"=>'',"status"=>"","orderCode"=>"","creater"=>"","order_type"=>0,"size"=>10,"page"=>1],"post","trim");
  504. $modela=['','payInfo','orderInfo','cgdInfo'];
  505. $sbtable = $modela[$param['order_type']];
  506. $type = [[],[1,2],[3,4],[5,6]];
  507. $where=[["tagInfo.type","in",$type[$param['order_type']]],["{$sbtable}.is_del","=",0],["tagInfo.is_del",'=',0]];
  508. empty($param['betweenTime'])?:$where[]=["tag_log.addtime","between",$param['betweenTime']];
  509. if($param['order_type']==1)$param['customerNo']==""?:$where[]=["{$sbtable}.customerNo","like","%{$param['customerNo']}%"];
  510. if($param['order_type']!=1)$param['supplierNo']==""?:$where[]=["{$sbtable}.supplierNo","like","%{$param['supplierNo']}%"];
  511. $param['companyNo']==""?:$where[]=["{$sbtable}.companyNo","like","%{$param['companyNo']}%"];
  512. $param['type']==''?:$where[]=["tagInfo.type","=",$param['type']];
  513. $param['status']===""?:$where[]=["tag_log.status","=",$param['status']];
  514. $param['orderCode']==""?:$where[]=["code","like","%{$param['orderCode']}%"];
  515. $param['creater']==""?:$where[]=["creater","like","%{$param['creater']}%"];
  516. $model =new TagLog();
  517. $list = $model->withJoin(["tagInfo",$sbtable],"left")->where($where)
  518. ->order("id","desc")
  519. ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
  520. $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  521. }
  522. }