Orderment.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Admin\controller;
  4. use app\BaseController;
  5. use think\Request;
  6. use think\facade\Db;
  7. class Orderment extends BaseController
  8. {
  9. /**
  10. * 显示资源列表
  11. *
  12. * @return \think\Response
  13. */
  14. public function list()
  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 = [['is_del',"=",1]];
  26. $companyNo = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :"";
  27. if($companyNo!=""){
  28. $condition[] = ["companyNo","=",$companyNo];
  29. }
  30. $inv_status = isset($post['inv_status'])&&$post['inv_status']!="" ? trim($post['inv_status']) :"";
  31. if($inv_status!=""){
  32. $condition[] = ["inv_status","=",$inv_status];
  33. }
  34. $fund_status = isset($post['fund_status'])&&$post['fund_status']!="" ? trim($post['fund_status']) :"";
  35. if($fund_status!=""){
  36. $condition[] = ["fund_status","=",$fund_status];
  37. }
  38. $starttime = isset($post['starttime'])&&$post['starttime']!="" ? $post['starttime'] :"";
  39. if($starttime!=""){
  40. $condition[] = ["addtime",">=",$starttime];
  41. }
  42. $endtime = isset($post['endtime'])&&$post['endtime']!="" ? $post['endtime']:"";
  43. if($endtime!=""){
  44. $condition[] = ["addtime","<=",$endtime];
  45. }
  46. $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
  47. $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
  48. $count = Db::name("order_pool")->where($condition)->count();
  49. $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
  50. $page = $page >= $total ? intval($total) : $page;
  51. $list = Db::name("order_pool")->where($condition)->page(intval($page), $size)->select();
  52. $data=[];
  53. foreach ($list as $value){
  54. $customer = Db::name("customer_info")->where("companyNo","=",$value['companyNo'])->find();
  55. $value['companyName'] = isset($customer['companyName']) ?$customer['companyName']:"" ;
  56. $value['contactor'] = isset($customer['contactor']) ?$customer['contactor']:"";
  57. $goodlist = Db::name("order_info")->where("orderNo","=",$value['orderNo'])->select();
  58. $value['goodlist'] = $goodlist;
  59. $data[]=$value;
  60. }
  61. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  62. }
  63. /**
  64. * 显示创建资源表单页.
  65. *
  66. * @return \think\Response
  67. */
  68. public function create()
  69. {
  70. $post = $this->request->post();
  71. $token = isset($post['token']) ? trim($post['token']) : "";
  72. if ($token == "") {
  73. return error_show(101, 'token不能为空');
  74. }
  75. $effetc = VerifyTokens($token);
  76. if (!empty($effetc) && $effetc['code'] != 0) {
  77. return error_show($effetc['code'], $effetc['message']);
  78. }
  79. $type = isset($post['type']) && $post['type']!="" ? $post['type'] : "";
  80. if($type==""){
  81. return error_show(1003,"参数type 不能为空");
  82. }
  83. $company = isset($post['company']) && $post['company']!="" ? $post['company'] : "";
  84. if($company==""){
  85. return error_show(1003,"参数company 不能为空");
  86. }
  87. $goodid = isset($post['goodid']) && $post['goodid']!="" ? $post['goodid'] : "";
  88. if($goodid==""){
  89. return error_show(1003,"参数goodid 不能为空");
  90. }
  91. if($type==1){
  92. $goodlist = Db::name("qrd_list")->where("id","in",$goodid)->field("sequenceNo,goodname,brand,unit,num,price,total_fee,diff_price")->select();
  93. if(empty($goodlist)){
  94. return error_show(1003,"未找到对应的商品");
  95. }
  96. }
  97. $userinfo = GetUserInfo($token);
  98. if(!isset($userinfo['code'])|| $userinfo['code']!=0){
  99. return error_show(101,'未能获取用户信息');
  100. }
  101. $nickname = $userinfo['data']["nickname"];
  102. $uid = $userinfo['data']['id'];
  103. $orderNo = makeNo("ORD");
  104. $data=[
  105. "orderNo"=>$orderNo,
  106. "companyNo"=>$company,
  107. "sales_id"=>$uid,
  108. "sales_name"=>$nickname,
  109. "total_amount"=>0,
  110. "inv_status"=>0,
  111. "fund_status"=>0,
  112. "status"=>0,
  113. "addtime"=>date("Y-m-d H:i:s"),
  114. "updatetime"=>date("Y-m-d H:i:s")
  115. ];
  116. Db::startTrans();
  117. try{
  118. $orderinfo=[];
  119. foreach ($goodlist as $value){
  120. $temp=[];
  121. $temp['orderNo']= $orderNo;
  122. $temp['goodNo']= $value['sequenceNo'];
  123. $temp['good_name']= $value['goodname'];
  124. $temp['type_name']= $value['brand'];
  125. $temp['unit']=$value['unit'];
  126. $temp['good_num']=$value['num'];
  127. $temp['price']=$value['price'];
  128. $temp['other_fee']=$value['diff_price'];
  129. $temp['total_fee']=$value['total_fee'];
  130. $temp['status']=1;
  131. $temp['addtime']=date("Y-m-d H:i:s");
  132. $temp['updatetime']=date("Y-m-d H:i:s");
  133. $data['total_amount'] += $value['total_fee'];
  134. $orderinfo[]=$temp;
  135. }
  136. $num = Db::name("order_info")->insertAll($orderinfo);
  137. if($num>0){
  138. $orderin = Db::name("order_pool")->insert($data);
  139. if($orderin){
  140. Db::commit();
  141. return app_show(0,"新建成功");
  142. }
  143. }
  144. Db::rollback();
  145. return error_show(1004,"新建失败");
  146. }catch (\Exception $e){
  147. Db::rollback();
  148. return error_show(1004,$e->getMessage());
  149. }
  150. }
  151. /**
  152. * 财务需求的数据列表
  153. * @param \think\Request $request
  154. * @return \think\Response
  155. */
  156. public function CWlist()
  157. {
  158. $post = request()->post();
  159. // $token = isset($post['token']) ? trim($post['token']) : "";
  160. // if ($token == "") {
  161. // return error_show(101, 'token不能为空');
  162. // }
  163. // $effetc = VerifyTokens($token);
  164. // if (!empty($effetc) && $effetc['code'] != 0) {
  165. // return error_show($effetc['code'], $effetc['message']);
  166. // }
  167. $condition="1=1";
  168. $qrd_start = isset($post['qrd_start']) && $post['qrd_start'] != "" ? $post['qrd_start'] :"" ;
  169. if($qrd_start!=""){
  170. $condition .=" and ordertime>='". $qrd_start." 00:00:00'";
  171. }
  172. $qrd_end = isset($post['qrd_end']) && $post['qrd_end'] != "" ? $post['qrd_end'] :"" ;
  173. if($qrd_end!=""){
  174. $condition .=" and ordertime <='". $qrd_end." 23:59:59'";
  175. }
  176. $hk_start = isset($post['hk_start']) && $post['hk_start'] != "" ? $post['hk_start'] :"" ;
  177. $hk_end = isset($post['hk_end']) && $post['hk_end'] != "" ? $post['hk_end'] :"" ;
  178. if($hk_start!=""){
  179. $condition .=" and addtime >='". $hk_start." 00:00:00'";
  180. }
  181. if($hk_end!=""){
  182. $condition .=" and addtime <='". $hk_end." 23:59:59'";
  183. }
  184. if($qrd_start==""&&$hk_start==""){
  185. $condition .=" and ordertime>='". date("Y-m-d")." 00:00:00'";
  186. }
  187. $count = Db::name("cw_report")->where($condition)->count();
  188. $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
  189. $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
  190. $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
  191. $page = $page >= $total ? intval($total) : $page;
  192. $list = Db::name("cw_report")->where($condition)->page($page,$size)->order('ordertime')->select();
  193. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  194. }
  195. /**
  196. * 显示指定的资源
  197. *
  198. * @param int $id
  199. * @return \think\Response
  200. */
  201. public function read($id)
  202. {
  203. //
  204. }
  205. /**
  206. * 显示编辑资源表单页.
  207. *
  208. * @param int $id
  209. * @return \think\Response
  210. */
  211. public function edit($id)
  212. {
  213. //
  214. }
  215. /**
  216. * 保存更新的资源
  217. *
  218. * @param \think\Request $request
  219. * @param int $id
  220. * @return \think\Response
  221. */
  222. public function update(Request $request, $id)
  223. {
  224. //
  225. }
  226. /**
  227. * 删除指定资源
  228. *
  229. * @param int $id
  230. * @return \think\Response
  231. */
  232. public function delete($id)
  233. {
  234. //
  235. }
  236. }