wugg 1 год назад
Родитель
Сommit
7d8e6f98e4

+ 1 - 1
.env

@@ -1 +1 @@
-APP_DEBUG = true

default_admin_addcount_role_id = 1
default_supplier_addcount_role_id = 50


[APP]
DEFAULT_TIMEZONE = Asia/Shanghai


[LANG]
default_lang = zh-cn

[USER]
hosturl=http://user.test241.wanyuhengtong.com/


#主数据库
[database]
type=mysql
hostname=120.46.155.214
database=wsm3_pre_release
username=root
password=test!@#wyht123
charset=utf8
prefix=wsm_


[mysql3]
type=mysql
hostname=120.46.155.214
database=inv
username=root
password=test!@#wyht123
charset=utf8
prefix=cfp_

#有赞数据库
[mysql_yz]
type=mysql
hostname=120.46.155.214
database=youzan
username=root
password=test!@#wyht123
hostport=3306
charset=utf8
prefix=yz_


#账号数据库
[mysql_sys]
type=mysql
hostname=120.46.155.214
database=sys_user_pre_release
username=root
password=test!@#wyht123
hostport=3306
charset=utf8
prefix=sys_



#结算平台数据库
[mysql_cxinv]
type=mysql
hostname=120.46.155.214
database=cxinv_v2_pre_release
username=root
password=test!@#wyht123
hostport=3306
charset=utf8
prefix=cfp_
+APP_DEBUG = true

default_admin_addcount_role_id = 1
default_supplier_addcount_role_id = 50


[APP]
DEFAULT_TIMEZONE = Asia/Shanghai


[LANG]
default_lang = zh-cn

[USER]
hosturl=http://user.test241.wanyuhengtong.com/


#主数据库
[database]
type=mysql
hostname=120.46.155.214
database=wsm3_pre_release
username=admin
password=admin!@#865
charset=utf8
prefix=wsm_


[mysql3]
type=mysql
hostname=120.46.155.214
database=inv
username=admin
password=admin!@#865
charset=utf8
prefix=cfp_

#有赞数据库
[mysql_yz]
type=mysql
hostname=120.46.155.214
database=youzan
username=admin
password=admin!@#865
hostport=3306
charset=utf8
prefix=yz_


#账号数据库
[mysql_sys]
type=mysql
hostname=120.46.155.214
database=sys_user_pre_release
username=admin
password=admin!@#865
hostport=3306
charset=utf8
prefix=sys_



#结算平台数据库
[mysql_cxinv]
type=mysql
hostname=120.46.155.214
database=cxinv_v2_pre_release
username=admin
password=admin!@#865
hostport=3306
charset=utf8
prefix=cfp_

+ 2 - 1
app/admin/controller/After.php

@@ -540,7 +540,8 @@ class After extends Base
             switch ($info['status']) {
                 case 1:
                     if (in_array($param['status'], [6, 2, 9]) == false) throw new Exception('选项错误');
-                    if ($info['order_type'] == 1 && $param['status'] != 2) throw new Exception('选项错误');//库存品不允许供应商审核,只允许走2-11-4-12-5流程
+                    if ($info['order_type'] == 1 && $param['status'] == 9) throw new Exception('选项错误');
+                    //库存品不允许供应商审核,只允许走2-11-4-12-5流程
                     break;
                 case 9:
                     if ((($info['is_receive'] == 1) && (in_array($param['status'], [2, 4]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [2, 5]) == false)))) throw new Exception('选项错误');

+ 18 - 0
app/model/AccountItem.php

@@ -0,0 +1,18 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class AccountItem extends Model
+{
+    protected $connection='mysql_sys';
+    
+    public function GetUidByDepartId($departId){
+        return $this->where(["itemid"=>$departId])->column("account_id");
+    }
+}

+ 60 - 0
app/report/controller/Base.php

@@ -0,0 +1,60 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\controller;
+
+use app\BaseController;
+use app\model\AccountItem;use think\App;
+use think\facade\Cache;use think\Response;
+use think\exception\HttpResponseException;
+class Base extends BaseController
+{
+	  protected $responseType = 'json';
+    public function __construct(App $app) {parent::__construct($app);}
+    
+      public function result(string $msg, $data = null, int $code = 0, string $type = null, array $header = [], array $options = [])
+    {
+        $result = [
+            'code' => $code,
+            'msg'  => $msg,
+            'data' => $data,
+        ];
+        // 如果未设置类型则自动判断
+        $type = $type ?:  $this->responseType;
+
+        $code = 200;
+        if (isset($header['statuscode'])) {
+            $code = $header['statuscode'];
+            unset($header['statuscode']);
+        }
+
+        $response = Response::create($result, $type, $code)->header($header)->options($options);
+         throw new HttpResponseException($response);
+    }
+    
+     /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+    public function error($message='',$code=1004,$data=null){
+        $this->result($message,$data,$code);
+    }
+    /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+     public function success($message='',$data=null,$code=0){
+        $this->result($message,$data,$code);
+    }
+    public function  GetDepartId($derpar_id){
+     	$uid=Cache::get("Report::depart_".$derpar_id);
+     	if($uid==false){
+     		$uid = (new AccountItem())->GetUidByDepartId($derpar_id);
+     		Cache::set('Report::depart_'.$derpar_id,$uid,new \DateTime(date("Y-m-d 23:59:59")));
+     	}
+     	
+     	return $uid;
+    }
+}

+ 323 - 0
app/report/controller/Stats.php

@@ -0,0 +1,323 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\controller;
+
+use app\model\AccountItem;use app\report\model\ConsultBids;use app\report\model\ConsultInfo;use app\report\model\ConsultOrder;
+use app\report\model\OrderOut;use app\report\model\OrderOutChild;use app\report\model\Purchease;
+use app\report\model\PurcheaseOrder;
+use app\report\model\Sale;
+use think\db\Query;use think\Request;
+use think\App;
+class Stats extends Base
+{
+	private $saleDerpart=[52=>'客服部@百辰荣达',53=>'项目部@普润心堂',56=>'网络部@泓源广诚',57=>'平台部@万宇恒通',59=>'财务部@万宇恒通']; //  客服部@百辰荣达,
+	//项目部@普润心堂,网络部@泓源广诚,平台部@万宇恒通,财务部@万宇恒通
+	private $cgdDerpart=[58=>"万宇供应链资源部"];//万宇供应链资源部
+	public function __construct(App $app) {parent::__construct($app);}
+	
+	//咨询单
+    public function zxorder()
+    {
+    	$param =$this->request->param(["start"=>date("Y-m-01 00:00:00"),"end"=>date("Y-m-t 23:59:59")]);
+    	$time = [$param["start"],$param['end']];
+    	$zxModel =new ConsultOrder();
+    	$temp=[];
+    	foreach ($this->saleDerpart as $departid=>$depart){
+    	    $uid =$this->GetDepartId($departid);
+    	    $temp[$departid]["name"] =$depart;
+    	    $temp[$departid]["num"] =$zxModel->alias("a")->leftJoin("consult_info b","wsm_consult_order.zxNo=b.zxNo")
+    	    ->whereBetween('b.addtime',$time)
+    	    ->whereIn('createrid',$uid)
+    	    ->where(["a.is_del"=>0,"b.is_del"=>0])
+    	    ->count();
+    	}
+    	
+         $this->success("获取成功",$temp);
+    }
+
+    /**
+     * 销售单.
+     *
+     * @return \think\Response
+     */
+    public function saleOrder()
+    {
+    	$param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
+    	$time = [$param['start'],$param['end']];
+    	$Model =new Sale();
+    	$temp=[];
+    	foreach ($this->saleDerpart as $departid=>$depart){
+    	    $uid =$this->GetDepartId($departid);
+    	    $temp[$departid]['name'] =$depart;
+    	    $temp[$departid]['result'] =$Model->group("order_type")
+    	    ->whereBetween('addtime',$time)
+    	    ->whereIn('apply_id',$uid)
+    	    ->where(['is_del'=>0])
+    	    ->column("count(1) num,order_type","order_type");
+    	}
+    	
+         $this->success('获取成功',$temp);
+    }
+
+    /**
+     * 报备单
+     *
+     * @param  \think\Request  $request
+     * @return \think\Response
+     */
+    public function bkOrder()
+    {
+       $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
+    	$time = [$param['start'],$param['end']];
+    	$Model =new Purchease();
+    	$temp=[];
+    	foreach ($this->saleDerpart as $departid=>$depart){
+    	    $uid =$this->GetDepartId($departid);
+    	    $temp[$departid]['name'] =$depart;
+    	    $temp[$departid]['num'] =$Model
+    	    ->whereBetween('addtime',$time)
+    	    ->whereIn('apply_id',$uid)
+    	    ->where(['is_del'=>0,"status"=>[1,2]])
+    	    ->count();
+    	}
+    	
+         $this->success('获取成功',$temp);
+    }
+
+    /**
+     * 采购部门采购情况
+     */
+    public function cgdOrder()
+    {
+     $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
+     $time = [$param['start'],$param['end']];
+    	$Model =new PurcheaseOrder();
+    	$temp=[];
+    	
+    	foreach ($this->cgdDerpart as $departid=>$depart){
+    	    $uid =$this->GetDepartId($departid);
+    	    $temp[$departid]['name'] =$depart;
+    	    
+    	    $data =$Model->alias("a")->leftJoin("order_num b","a.cgdNo=b.cgdNo")
+    	    ->leftJoin("sale c","c.orderCode=b.orderCode and c.is_del=0")
+    	    ->leftJoin("platform d","d.id=c.platform_id and d.is_del=0")
+    	    ->field("a.cgder,a.cgder_id,a.order_type,d.use_type,count(1) num")
+    	    ->group("a.cgder,a.cgder_id,order_type,use_type")
+    	     ->whereBetween('a.addtime',$time)
+    	    ->whereIn('a.cgder_id',$uid)
+    	    ->where('a.is_del',0)
+    	    ->select();
+    	    $result=[];
+    	    foreach ($data as $key=>$val){
+    	    	if(!isset($result[$val['cgder_id']])){
+    	    		 $result[$val['cgder_id']]= [  'cgder'=>$val['cgder'],
+	                    'total_cgd' => 0,//订单总量
+	                    'tag_1' => 0,//库存品
+	                    'tag_2' => 0,//非库存品
+	                    'tag_zx' => 0,//咨询采反总数
+	                    'tag_c' => 0,//to C
+	                    'tag_b' => 0,//to B
+                    ];
+    	    	}
+    	    	switch ($val['order_type']) {
+	                case 1:
+	                    //库存品
+	                    if ($val['order_source'] == 0) {
+	                        $result[$val['cgder_id']]['tag_1']+=$val['num'];
+	                    }
+	                    break;
+	
+	                case 2:
+	                    //非库存品
+	                 $result[$val['cgder_id']]['tag_2']+=$val['num'];
+					break;
+	                case 3:
+	                    //咨询采反
+						$result[$val['cgder_id']]['tag_zx']+=$val['num'];
+	                    break;
+                }
+                
+              switch ($val['use_type']) {
+	                case 1:
+	                    //to B
+	                    $result[$val['cgder_id']]['tag_b']+=$val['num'];
+	                    
+	                    break;
+	
+	                case 2:
+	                    //to C
+	                      $result[$val['cgder_id']]['tag_c']+=$val['num'];
+	                    break;
+                }
+    	    }
+    	    $temp[$departid]['result'] =$result;
+    	    
+    	}
+         $this->success('获取成功',$temp);
+    }
+
+    /**
+     * 显示编辑资源表单页.
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function bidsOrder()
+    {
+     $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
+     $time = [$param['start'],$param['end']];
+     $model = new ConsultBids();
+     $temp=[];
+      foreach ($this->cgdDerpart as $departid=>$depart){
+            $uid =$this->GetDepartId($departid);
+    	    $temp[$departid]['name'] =$depart;
+    	    $list = $model->whereBetween("addtime",$time)->whereIn("createrid",$uid)->where('is_del',0)->group("createrid,creater")->field
+    	    ("creater,createrid,count(1) num")->select();
+    	    $temp[$departid]['result'] =$list;
+      }
+          $this->success('获取成功',$temp);
+    }
+
+    /**
+     * 咨询单空返数据
+     *
+     * @param  \think\Request  $request
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function bidsFail()
+    {$param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
+     $time = [$param['start'],$param['end']];
+     $model = new ConsultOrder();
+     $temp=[];
+     $uid =	 (new AccountItem())->GetUidByDepartId(array_keys($this->saleDerpart));
+     $list = $model->alias('a')
+    	    ->leftJoin('consult_info b','wsm_consult_order.zxNo=b.zxNo')
+    	    ->whereBetween('a.addtime',$time)
+    	    ->whereIn('createrid',$uid)
+    	    ->where(['a.is_del'=>0,'b.is_del'=>0])
+    	    ->where('b.status','<>',5)
+    	    ->group('b.status')
+    	    ->column('b.status,count(1) num','b.status');
+    	    $temp['result'] =$list;
+      $this->success('获取成功',$temp);
+    }
+
+    /**
+     * 发货工单
+     */
+    public function outChildOrder()
+    {
+      $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
+      $time = [$param['start'],$param['end']];
+      $model = new OrderOutChild();
+      foreach ($this->saleDerpart as $departid=>$sale){
+      	$uid = $this->GetDepartId($departid);
+      	 $temp[$departid]['name'] =$sale;
+      	   $build=  $model->alias('a')->LeftJoin('warehouse_info b','a.wsm_code=b.wsm_code')
+      	 ->whereBetween('a.addtime',$time)
+      	 ->whereIn('a.apply_id',$uid)
+      	 ->where('a.is_del',0)
+      	 ->field('a.id,ifnull(b.contactor,"0") contactor,ifnull(b.contactor_name,"") as contactor_name ,a.addtime,DATEDIFF(ifnull( a.sendtime, NOW()), a.addtime ) as expire,"" stage')
+      	 ->withAttr('stage',function ($v,$row){
+      	 	if($row['expire']==0) return 1;
+      	 	elseif($row['expire']<2) return 2;
+      	 	elseif($row['expire']< 7) return 3;
+      	 	elseif($row['expire']< 14) return 4;
+      	 	elseif($row['expire']< 30) return 5;
+      	 	else return 6;
+      	 })->select();
+      	  $tlist=[];
+      	foreach ($build as $item){
+      	    if(!isset($tlist[$item['contactor']])){
+      	    	$tlist[$item['contactor']]=[$item['contactor_name'],0,0,0,0,0,0];
+      	    }
+      	    $tlist[$item['contactor']][$item['stage']]+=1;
+      	}
+      	 $temp[$departid]['result'] =$tlist?:[];
+      }
+      $this->success('获取成功',$temp);
+    }
+    
+    /** 发货单数据统计
+	* @throws \think\db\exception\DataNotFoundException
+	* @throws \think\db\exception\DbException
+	* @throws \think\db\exception\ModelNotFoundException
+    */
+    public function outOrder()
+    {
+      $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
+      $time = [$param['start'],$param['end']];
+      $model = new OrderOut();
+      foreach ($this->saleDerpart as $departid=>$sale){
+      	$uid = $this->GetDepartId($departid);
+      	 $temp[$departid]['name'] =$sale;
+      	  $build=  $model->alias('a')->LeftJoin('warehouse_info b','a.wsm_code=b.wsm_code')
+      	 ->whereBetween('a.addtime',$time)
+      	 ->whereIn('a.apply_id',$uid)
+      	 ->where('a.is_del',0)
+      	 ->field('a.id,ifnull(b.contactor,"0") contactor,ifnull(b.contactor_name,"") as contactor_name ,a.addtime,DATEDIFF(ifnull( a.sendtime, NOW()), a.addtime ) as expire,"" stage')
+      	 ->withAttr('stage',function ($v,$row){
+      	 	if($row['expire']==0) return 1;
+      	 	elseif($row['expire']<2) return 2;
+      	 	elseif($row['expire']< 7) return 3;
+      	 	elseif($row['expire']< 14) return 4;
+      	 	elseif($row['expire']< 30) return 5;
+      	 	else return 6;
+      	 })->select();
+      	  $tlist=[];
+      	foreach ($build as $item){
+      	    if(!isset($tlist[$item['contactor']])){
+      	    	$tlist[$item['contactor']]=[$item['contactor_name'],0,0,0,0,0,0];
+      	    }
+      	    $tlist[$item['contactor']][$item["stage"]]+=1;
+      	}
+      	 $temp[$departid]['result'] =$tlist;
+      }
+      $this->success('获取成功',$temp);
+    }
+    //未发货数据
+    public function wsendOrder(){
+    	
+    	$temp=[];
+    	$model =new Sale();
+		$userArr=[];
+    	foreach ($this->saleDerpart as $departid=>$depart){
+    		$uid = $this->GetDepartId($departid);
+    		$userArr=array_merge($userArr,$uid);
+    		$temp[$departid]["name"] = $depart;
+    	    $start = 1;
+    	    $end = date("m");
+    		while ($start<=$end){
+    			$list = $model->whereIn('status',[0,1])
+    			->whereIn("send_status",[1,2])
+	            ->whereIn('apply_id',$uid)
+	            ->whereMonth('addtime',date('Y').'-'.$start)
+	            ->group('send_status')->column('sum(wsend_num) num','send_status');
+    			$temp[$departid]['result'][$start]=$list;
+    			$start++;
+    		}
+    		
+    	}
+    	$noArr=[];
+    	$noArr['name'] = "无地址订单";
+    	 $start = 1;
+    	    $end = date('m');
+    		while ($start<=$end){
+//    			$month = $start;
+    			$list = $model->whereIn('status',[0,1])
+    			->whereIn('send_status',[1,2])
+	            ->whereIn('apply_id',$userArr)
+	            ->whereMonth('addtime',date('Y').'-'.$start)
+	            ->field("sale_price,orderCode")
+	            ->append(["no_addr_num"=>function(Query $query,$data){
+	            	$query->name('order_addr')->where(['orderCode'=>$data['orderCode'],'is_del'=>0])->sum('receipt_quantity');
+	            }])
+	            ->find();
+    			$noArr['result'][$start]['total_price']=bcmul($list['sale_price'],$list['no_addr_num'].'',2);
+    			$start++;
+    		}
+    	  $this->success('获取成功',["result"=>$temp,"noAddr"=>$noArr]);
+    }
+}

+ 14 - 0
app/report/model/ConsultBids.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ConsultBids extends Model
+{
+    //
+}

+ 17 - 0
app/report/model/ConsultInfo.php

@@ -0,0 +1,17 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ConsultInfo extends Model
+{
+    
+	public function zxorder(){
+		return $this->belongsTo(ConsultOrder::class,"zxNo","zxNo")->bind(["creater","createrid"]);
+	}
+}

+ 16 - 0
app/report/model/ConsultOrder.php

@@ -0,0 +1,16 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ConsultOrder extends Model
+{
+   public function zxinfo(){
+   	return $this->belongsToMany(ConsultInfo::class,"zxNo","zxNo");
+   }
+}

+ 14 - 0
app/report/model/OrderOut.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderOut extends Model
+{
+    //
+}

+ 22 - 0
app/report/model/OrderOutChild.php

@@ -0,0 +1,22 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderOutChild extends Model
+{
+//	protected $append=["expire"];
+//	public function GetExpireAttr($v,$row){
+//		return date_diff(new \DateTime($row['sendtime']??date("Y-m-d H:i:s")),new \DateTime($row['addtime']))->days+1;
+//	}
+    public function WsmInfo(){
+    	return $this->belongsTo(Ware::class,"wsm_code","wsm_code")->bind(["contactor","contactor_name"]);
+    }
+    
+    
+}

+ 14 - 0
app/report/model/Purchease.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Purchease extends Model
+{
+    //
+}

+ 14 - 0
app/report/model/PurcheaseOrder.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class PurcheaseOrder extends Model
+{
+
+}

+ 14 - 0
app/report/model/Sale.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Sale extends Model
+{
+
+}

+ 16 - 0
app/report/model/Ware.php

@@ -0,0 +1,16 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Ware extends Model
+{
+  
+//   protected $prefix='wsm_';
+    protected $name='warehouse_info';
+}

+ 3 - 0
app/report/route/app.php

@@ -0,0 +1,3 @@
+<?php
+use think\facade\Route;
+