Supplier.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Admin\controller;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. use think\Request;
  7. class Supplier extends BaseController
  8. {
  9. /**
  10. * 显示资源列表
  11. *
  12. * @return \think\Response
  13. */
  14. public function SupplierList()
  15. {
  16. $post =$this->request->post();
  17. $token = isset($post['token']) ? trim($post['token']) : "";
  18. if($token==""){
  19. return error_show(101,'token不能为空');
  20. }
  21. $effetc = VerifyTokens($token);
  22. if(!empty($effetc) && $effetc['code']!=0){
  23. return error_show($effetc['code'],$effetc['message']);
  24. }
  25. $condition = "1=1 ";
  26. // $userinfo = GetUserInfo($token);
  27. // if(!isset($userinfo['code'])|| $userinfo['code']!=0){
  28. // return error_show(101,'未能获取用户信息');
  29. // }
  30. // $check = checkRole($userinfo['data']['roleid'],40);
  31. // if($check){
  32. // $condition .=" and (staffer = {$userinfo['data']['nickname']} or staffer ='')";
  33. //
  34. // }
  35. $name= isset($post['name'])&&$post['name']!="" ? trim($post['name']) :"";
  36. //$contector= isset($post['contector'])&&$post['contector']!="" ? trim($post['contector']) :"";
  37. // $staff= isset($post['staff'])&&$post['staff']!="" ? trim($post['staff']) :"";
  38. if($name!=""){
  39. $condition .=" and (name like '%{$name}%' or contector like '%{$name}%')";
  40. }
  41. // if($contector!=""){
  42. // $condition .=" and contector like '%{$contector}%'";
  43. // }
  44. // if($staff!=""){
  45. // $condition .="name like `%{$name}%`";
  46. // }
  47. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
  48. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  49. $count = Db::name("supplier_info")->where($condition)->count();
  50. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  51. $page = $page>=$total?intval($total):$page;
  52. $list = Db::name("supplier_info")->where($condition)->page($page,$size)->field("id,code,name,contector,nature,mobile,address,post,addtime")->select();
  53. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  54. }
  55. /**
  56. * 显示创建资源表单页.
  57. *
  58. * @return \think\Response
  59. */
  60. public function SupplierInfo()
  61. {
  62. $post =$this->request->post();
  63. $token = isset($post['token']) ? trim($post['token']) : "";
  64. if($token==""){
  65. return error_show(101,'token不能为空');
  66. }
  67. $effetc = VerifyTokens($token);
  68. if(!empty($effetc) && $effetc['code']!=0){
  69. return error_show($effetc['code'],$effetc['message']);
  70. }
  71. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  72. if($sid==""){
  73. return error_show(1002,"参数d不能为空");
  74. }
  75. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  76. if($supplier==false){
  77. return error_show(1003,"供应商信息不存在");
  78. }
  79. $cgd = Db::name("pay")->where([["supplierNo","=",$supplier['code']],["status","<>",0]])
  80. ->field("id,payNo,pay_fee,wait_fee,status")->select();
  81. $list=["payment"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]],"invoice"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]]];
  82. foreach ($cgd as $key=>$value){
  83. $list['payment']['wait']['total']+= $value['wait_fee']*100;
  84. $list['payment']['already']['total']+= $value['pay_fee']*100;
  85. $paystage = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',">","4"],['status',"<>","9"]])
  86. ->sum('pay_fee');
  87. $paywait = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',"<","4"],
  88. ['status',"<>","9"]])
  89. ->sum('pay_fee');
  90. $list['invoice']['wait']['total']+= $paywait*100;
  91. $list['invoice']['already']['total']+= $paystage*100;
  92. if($value['status']==2){
  93. $list['payment']['already']["num"]++;
  94. }else{
  95. $list['payment']['wait']["num"]++;
  96. }
  97. }
  98. array_walk($list,function (&$v){
  99. $v['wait']['total'] = $v['wait']['total']/100;
  100. $v['already']['total'] = $v['already']['total']/100;
  101. });
  102. return app_show(0,"获取成功",$list);
  103. }
  104. /**
  105. * 保存新建的资源
  106. *
  107. * @param \think\Request $request
  108. * @return \think\Response
  109. */
  110. public function SupplierSave()
  111. {
  112. $post =$this->request->post();
  113. $token = isset($post['token']) ? trim($post['token']) : "";
  114. if($token==""){
  115. return error_show(101,'token不能为空');
  116. }
  117. $effetc = VerifyTokens($token);
  118. if(!empty($effetc) && $effetc['code']!=0){
  119. return error_show($effetc['code'],$effetc['message']);
  120. }
  121. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  122. if($sid==""){
  123. return error_show(1002,"参数d不能为空");
  124. }
  125. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  126. if($supplier==false){
  127. return error_show(1003,"供应商信息不存在");
  128. }
  129. $name= isset($post['name'])&& $post['name']!="" ? trim($post['name']) :"";
  130. if($name==""){
  131. return error_show(1002,"供货商名称不能为空");
  132. }
  133. $contector= isset($post['contector'])&& $post['contector']!="" ? trim($post['contector']) :"";
  134. if($contector==""){
  135. return error_show(1002,"联系人名称不能为空");
  136. }
  137. $mobile= isset($post['mobile'])&& $post['mobile']!="" ? trim($post['mobile']) :"";
  138. if($mobile==""){
  139. return error_show(1002,"联系人手机号不能为空");
  140. }
  141. if(!checkMobile($mobile)){
  142. return error_show(1002,"联系人手机号格式错误");
  143. }
  144. $pay_method= isset($post['pay_method'])&& $post['pay_method']!="" ? trim($post['pay_method']) :"";
  145. if($pay_method==""){
  146. return error_show(1002,"结账方式不能为空");
  147. }
  148. $paydays= isset($post['paydays'])&& $post['paydays']!="" ? trim($post['paydays']) :"";
  149. $return_ticket= isset($post['return_ticket'])&& $post['return_ticket']!="" ? trim($post['return_ticket']) :"";
  150. $data=[
  151. "id"=>$supplier['id'],
  152. "name"=>$name,
  153. "contector"=>$contector,
  154. "mobile"=>$mobile,
  155. "pay_method"=>$pay_method,
  156. "paydays"=>$paydays,
  157. "return_ticket"=>$return_ticket,
  158. "updatetime"=>date("Y-m-d H:i:s"),
  159. ];
  160. $save = Db::name("supplier_info")->save($data);
  161. return $save ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  162. }
  163. /**
  164. * 显示指定的资源
  165. *
  166. * @param int $id
  167. * @return \think\Response
  168. */
  169. public function SupplierStatus()
  170. {
  171. $post =$this->request->post();
  172. $token = isset($post['token']) ? trim($post['token']) : "";
  173. if($token==""){
  174. return error_show(101,'token不能为空');
  175. }
  176. $effetc = VerifyTokens($token);
  177. if(!empty($effetc) && $effetc['code']!=0){
  178. return error_show($effetc['code'],$effetc['message']);
  179. }
  180. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  181. if($sid==""){
  182. return error_show(1002,"参数d不能为空");
  183. }
  184. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  185. if($supplier==false){
  186. return error_show(1003,"供应商信息不存在");
  187. }
  188. $status= isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  189. if($status==""){
  190. return error_show(1002,"参数status不能为空");
  191. }
  192. $data=[
  193. "id"=>$sid,
  194. "status"=>$status,
  195. "updatetime"=>date("Y-m-d H:i:s")
  196. ];
  197. $udap = DB::name("supplier_ifno")->save($data);
  198. return $udap ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  199. }
  200. /**
  201. * 显示编辑资源表单页.
  202. *
  203. * @param int $id
  204. * @return \think\Response
  205. */
  206. public function SupplierAdd($id)
  207. {
  208. //
  209. }
  210. /**
  211. * 保存更新的资源
  212. *
  213. * @param \think\Request $request
  214. * @param int $id
  215. * @return \think\Response
  216. */
  217. public function update(Request $request, $id)
  218. {
  219. //
  220. }
  221. /**
  222. * 删除指定资源
  223. *
  224. * @param int $id
  225. * @return \think\Response
  226. */
  227. public function delete($id)
  228. {
  229. //
  230. }
  231. }