123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- declare (strict_types = 1);
- namespace app\Admin\controller;
- use app\BaseController;
- use think\Request;
- use think\facade\Db;
- class Orderment extends BaseController
- {
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function list()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $condition = [['is_del',"=",1]];
- $companyNo = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :"";
- if($companyNo!=""){
- $condition[] = ["companyNo","=",$companyNo];
- }
- $inv_status = isset($post['inv_status'])&&$post['inv_status']!="" ? trim($post['inv_status']) :"";
- if($inv_status!=""){
- $condition[] = ["inv_status","=",$inv_status];
- }
- $fund_status = isset($post['fund_status'])&&$post['fund_status']!="" ? trim($post['fund_status']) :"";
- if($fund_status!=""){
- $condition[] = ["fund_status","=",$fund_status];
- }
- $starttime = isset($post['starttime'])&&$post['starttime']!="" ? $post['starttime'] :"";
- if($starttime!=""){
- $condition[] = ["addtime",">=",$starttime];
- }
- $endtime = isset($post['endtime'])&&$post['endtime']!="" ? $post['endtime']:"";
- if($endtime!=""){
- $condition[] = ["addtime","<=",$endtime];
- }
- $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
- $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
- $count = Db::name("order_pool")->where($condition)->count();
- $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
- $page = $page >= $total ? intval($total) : $page;
- $list = Db::name("order_pool")->where($condition)->page(intval($page), $size)->select();
- $data=[];
- foreach ($list as $value){
- $customer = Db::name("customer_info")->where("companyNo","=",$value['companyNo'])->find();
- $value['companyName'] = isset($customer['companyName']) ?$customer['companyName']:"" ;
- $value['contactor'] = isset($customer['contactor']) ?$customer['contactor']:"";
- $goodlist = Db::name("order_info")->where("orderNo","=",$value['orderNo'])->select();
- $value['goodlist'] = $goodlist;
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- $post = $this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if ($token == "") {
- return error_show(101, 'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if (!empty($effetc) && $effetc['code'] != 0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $type = isset($post['type']) && $post['type']!="" ? $post['type'] : "";
- if($type==""){
- return error_show(1003,"参数type 不能为空");
- }
- $company = isset($post['company']) && $post['company']!="" ? $post['company'] : "";
- if($company==""){
- return error_show(1003,"参数company 不能为空");
- }
- $goodid = isset($post['goodid']) && $post['goodid']!="" ? $post['goodid'] : "";
- if($goodid==""){
- return error_show(1003,"参数goodid 不能为空");
- }
- if($type==1){
- $goodlist = Db::name("qrd_list")->where("id","in",$goodid)->field("sequenceNo,goodname,brand,unit,num,price,total_fee,diff_price")->select();
- if(empty($goodlist)){
- return error_show(1003,"未找到对应的商品");
- }
- }
- $userinfo = GetUserInfo($token);
- if(!isset($userinfo['code'])|| $userinfo['code']!=0){
- return error_show(101,'未能获取用户信息');
- }
- $nickname = $userinfo['data']["nickname"];
- $uid = $userinfo['data']['id'];
- $orderNo = makeNo("ORD");
- $data=[
- "orderNo"=>$orderNo,
- "companyNo"=>$company,
- "sales_id"=>$uid,
- "sales_name"=>$nickname,
- "total_amount"=>0,
- "inv_status"=>0,
- "fund_status"=>0,
- "status"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- Db::startTrans();
- try{
- $orderinfo=[];
- foreach ($goodlist as $value){
- $temp=[];
- $temp['orderNo']= $orderNo;
- $temp['goodNo']= $value['sequenceNo'];
- $temp['good_name']= $value['goodname'];
- $temp['type_name']= $value['brand'];
- $temp['unit']=$value['unit'];
- $temp['good_num']=$value['num'];
- $temp['price']=$value['price'];
- $temp['other_fee']=$value['diff_price'];
- $temp['total_fee']=$value['total_fee'];
- $temp['status']=1;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $data['total_amount'] += $value['total_fee'];
- $orderinfo[]=$temp;
- }
- $num = Db::name("order_info")->insertAll($orderinfo);
- if($num>0){
- $orderin = Db::name("order_pool")->insert($data);
- if($orderin){
- Db::commit();
- return app_show(0,"新建成功");
- }
- }
- Db::rollback();
- return error_show(1004,"新建失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- /**
- * 财务需求的数据列表
- * @param \think\Request $request
- * @return \think\Response
- */
- public function CWlist()
- {
- $post = request()->post();
- // $token = isset($post['token']) ? trim($post['token']) : "";
- // if ($token == "") {
- // return error_show(101, 'token不能为空');
- // }
- // $effetc = VerifyTokens($token);
- // if (!empty($effetc) && $effetc['code'] != 0) {
- // return error_show($effetc['code'], $effetc['message']);
- // }
- $condition="1=1";
- $qrd_start = isset($post['qrd_start']) && $post['qrd_start'] != "" ? $post['qrd_start'] :"" ;
- if($qrd_start!=""){
- $condition .=" and ordertime>='". $qrd_start." 00:00:00'";
- }
- $qrd_end = isset($post['qrd_end']) && $post['qrd_end'] != "" ? $post['qrd_end'] :"" ;
- if($qrd_end!=""){
- $condition .=" and ordertime <='". $qrd_end." 23:59:59'";
- }
- $hk_start = isset($post['hk_start']) && $post['hk_start'] != "" ? $post['hk_start'] :"" ;
- $hk_end = isset($post['hk_end']) && $post['hk_end'] != "" ? $post['hk_end'] :"" ;
- if($hk_start!=""){
- $condition .=" and addtime >='". $hk_start." 00:00:00'";
- }
- if($hk_end!=""){
- $condition .=" and addtime <='". $hk_end." 23:59:59'";
- }
- if($qrd_start==""&&$hk_start==""){
- $condition .=" and ordertime>='". date("Y-m-d")." 00:00:00'";
- }
- $count = Db::name("cw_report")->where($condition)->count();
- $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
- $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
- $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
- $page = $page >= $total ? intval($total) : $page;
- $list = Db::name("cw_report")->where($condition)->page($page,$size)->order('ordertime')->select();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- //
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit($id)
- {
- //
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- //
- }
- }
|