Просмотр исходного кода

Merge branch 'dev-wgg' of wugg/cxinv into dev

wugg 2 лет назад
Родитель
Сommit
7ede5bffbf

+ 19 - 18
app/admin/controller/DepartTips.php

@@ -18,9 +18,9 @@ class DepartTips extends \app\admin\BaseController{
 		if($post["month"]!=='') $where[]=["month","=",$post["month"]];
 		if($post["companyNo"]!=='') $where[]=["companyNo","=",$post["companyNo"]];
 		$count =Db::name("depart_tips")->where($where)->count();
-		$total = ceil($count/$post['szie']);
+		$total = ceil($count/$post['size']);
 		$page = $total>=$post["page"]? intval($post['page']): intval($total);
-		$list = Db::name("depart_tips")->where($where)->page($page,intval($post['szie']))->select();
+		$list = Db::name("depart_tips")->where($where)->page($page,intval($post['size']))->order("id desc")->select();
 		return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
 	}
 
@@ -29,9 +29,9 @@ class DepartTips extends \app\admin\BaseController{
 		if($post['companyNo']=="") return error_show(1004,"业务公司编号不能为空");
 		if(empty($post['tips'])) return error_show(1004,"指标数据不能为空");
 		$rule =Validate::rule([
-			"year|年份"=>"require|number|Year",
-			"month|月份"=>"require|number|month",
-			"totl_tips|业绩指标"=>"require|float"
+			"year|年份"=>"require|number",
+			"month|月份"=>"require|number|between:1,12",
+			"total_tips|业绩指标"=>"require|float"
 			]);
 		$companyAr = UserHandle("getCodeAndName",["code"=>$post["companyNo"]]);
 		if(!isset($companyAr['code'])|| $companyAr['code']!=0)return error_show(1004,"业务公司信息未找到");
@@ -46,11 +46,11 @@ class DepartTips extends \app\admin\BaseController{
 			if(empty($ist))$inst[]=[
 				"companyNo"=>$post["companyNo"],
 				"companyName"=>$companyName,
-				"year"=>$post["year"],
-				"month"=>$post["month"],
-				"total_tips"=>$post["total_tips"]
+				"year"=>$item["year"],
+				"month"=>$item["month"],
+				"total_tips"=>$item["total_tips"]
 				];
-			else Db::name("depart_tips")->where($ist)->update(["total_tips"=>$post["total_tips"]]);
+			else Db::name("depart_tips")->where($ist)->update(["total_tips"=>$item["total_tips"]]);
 		}
 
 		if(!empty($inst))Db::name("depart_tips")->insertAll($inst);
@@ -69,9 +69,10 @@ class DepartTips extends \app\admin\BaseController{
 		if($post["month"]!=='') $where[]=["month","=",$post["month"]];
 		if($post["depart_id"]!=='') $where[]=["depart_id","=",$post["depart_id"]];
 		$count =Db::connect("mysql_wsm3.0")->name("depart_tips")->where($where)->count();
-		$total = ceil($count/$post['szie']);
+		$total = ceil($count/$post['size']);
 		$page = $total>=$post["page"]? intval($post['page']): intval($total);
-		$list = Db::connect("mysql_wsm3.0")->name("depart_tips")->where($where)->page($page,intval($post['szie']))->select();
+		$list = Db::connect("mysql_wsm3.0")->name("depart_tips")->where($where)->page($page,intval($post['size']))
+			->order("id desc")->select();
 		return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
 	}
 
@@ -80,9 +81,9 @@ class DepartTips extends \app\admin\BaseController{
 		if($post['depart_id']=="") return error_show(1004,"业务部门不能为空");
 		if(empty($post['tips'])) return error_show(1004,"指标数据不能为空");
 		$rule =Validate::rule([
-			"year|年份"=>"require|number|Year",
-			"month|月份"=>"require|number|month",
-			"totl_tips|业绩指标"=>"require|float"
+			"year|年份"=>"require|number",
+			"month|月份"=>"require|number|between:1,12",
+			"total_tips|业绩指标"=>"require|float"
 			]);
 		$companyAr = UserHandle("get_part",["itemid"=>$post["depart_id"]]);
 		if(!isset($companyAr['code'])|| $companyAr['code']!=0)return error_show(1004,"业务部门信息未找到");
@@ -97,11 +98,11 @@ class DepartTips extends \app\admin\BaseController{
 			if(empty($ist))$inst[]=[
 				"depart_id"=>$post["companyNo"],
 				"depart_item"=>$companyName,
-				"year"=>$post["year"],
-				"month"=>$post["month"],
-				"total_tips"=>$post["total_tips"]
+				"year"=>$item["year"],
+				"month"=>$item["month"],
+				"total_tips"=>$item["total_tips"]
 				];
-			else Db::connect("mysql_wsm3.0")->name("depart_tips")->where($ist)->update(["total_tips"=>$post["total_tips"]]);
+			else Db::connect("mysql_wsm3.0")->name("depart_tips")->where($ist)->update(["total_tips"=>$item["total_tips"]]);
 		}
 
 		if(!empty($inst))Db::connect("mysql_wsm3.0")->name("depart_tips")->insertAll($inst);

+ 77 - 0
app/admin/controller/WeChat.php

@@ -0,0 +1,77 @@
+<?php
+
+
+namespace app\admin\controller;
+
+use think\App;
+use app\admin\BaseController as Base;
+use think\facade\Validate;
+use think\facade\Db;
+class WeChat extends Base {
+	public $wechat;
+	public function __construct(App $App) {
+		parent::__construct($App);
+		$wechat_conf =env("wechat");
+		$this->wechat=new \think\Wechat($wechat_conf);
+	}
+//		获取用户信息
+//	    "userid": "zhangsan",
+//	 *    "name": "李四",
+//	 *    "department": [1, 2],
+//	 *    "position": "后台工程师",
+//	 *    "mobile": "15913215421",
+//	 *    "gender": 1,     //性别。gender=0表示男,=1表示女
+//	 *    "tel": "62394",
+//	 *    "email": "zhangsan@gzdev.com",
+//	 *    "weixinid": "lisifordev",        //微信号
+//	 *    "avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3W..../0",   //头像url。注:如果要获取小图将url最后的"/0"改成"/64"即可
+//	 *    "status": 1      //关注状态: 1=已关注,2=已冻结,4=未关注
+//	 *    "extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]}
+	public function getinfo(){
+		$code =$this->request->only(["code"=>""],"post","trim");
+		$valid =Validate::rule(["code|微信授权Code"=>"require|max:255|min:5"]);
+		if($valid->check($code)==false) return error_show(1004,$valid->getError());
+
+		$uid =$this->wechat->getUserId($code['code']);
+		if($uid==false){
+			return error_show(1004,"未获取到用户数据");
+		}
+		if(!isset($uid['UserId'])|| $uid['UserId'])	return error_show(1004,"未获取到用户数据");
+		$Dbuser =Db::name("wechat_user")->where(["userid"=>$uid['UserId']])->findOrEmpty();
+		if(empty($Dbuser)){
+			$useinfo = $this->wechat->getUserInfo($uid['UserId']);
+			if($useinfo==false)return error_show(1004,"未获取到用户数据");
+			$Dbuser = [
+				"userid"=>$useinfo['userid'],
+				"position"=>$useinfo['userid'],
+				"mobile"=>$useinfo['userid'],
+				"gender"=>$useinfo['userid'],
+				"tel"=>$useinfo['userid'],
+				"email"=>$useinfo['userid'],
+				"weixinid"=>$useinfo['userid'],
+				"avatar"=>$useinfo['userid'],
+				"status"=>$useinfo['userid'],
+				"extattr"=>$useinfo['userid'],
+				"addtime"=>date("Y-m-d H:i:s"),
+				"updatetime"=>date("Y-m-d H:i:s")
+				];
+			$Dbuser['id']=Db::name("wechat_user")->insertGetId($Dbuser);
+		}else
+			{
+				$Dbuser["updatetime"]=date("Y-m-d H:i:s");
+				Db::name("wechat_user")->save($Dbuser);
+			}
+		return app_show(0,"获取成功",$Dbuser);
+	}
+	//网页端调用jssdk配置config
+	public function getConfig(){
+		$url =$this->request->only(["url"=>""],"post","trim");
+		$valid =Validate::rule(["code|微信授权Code"=>"require|max:255|min:5"]);
+		if($valid->check($url)==false) return error_show(1004,$valid->getError());
+		$baseconfig =$this->wechat->getJsSign($url['url']);
+		if($baseconfig==false){
+			return error_show(1004,"为获取到用户数据");
+		}
+		return app_show(0,"获取成功",$baseconfig);
+	}
+}

+ 1 - 0
app/admin/controller/index.php

@@ -16,6 +16,7 @@ class index
      */
     public function index()
     {
+
     }
 
     /**

+ 5 - 1
app/admin/middleware/checkToken.php

@@ -17,7 +17,11 @@ class checkToken
 		"admin/stats",
 		"admin/departstat",
 		"admin/departEveryDay",
-		"admin/totalstat"];
+		"admin/companyEveryMonth",
+		"admin/wechat_getinfo",
+		"admin/wechat_getconfig",
+		"admin/totalstat"
+		];
     /**
      * 处理请求
      *

+ 4 - 0
app/admin/route/app.php

@@ -248,9 +248,13 @@ route::rule("stats","admin/Stat/stats");//网络部录单分类
 route::rule("departstat","admin/Stat/depart");//网络部录单分类
 route::rule("totalstat","admin/Stat/Total");//网络部录单分类
 route::rule("departEveryDay","admin/Stat/departEveryDay");//网络部录单分类
+route::rule("companyEveryMonth","admin/Stat/companyEveryMonth");//网络部录单分类
 
 route::rule("companytipslist","admin/DepartTips/list");//网络部录单分类
 route::rule("companytipsadd","admin/DepartTips/create");//网络部录单分类
 route::rule("departtipslist","admin/DepartTips/departlist");//网络部录单分类
 route::rule("departtipsadd","admin/DepartTips/departcreate");//网络部录单分类
 
+route::rule("wechat_getinfo","admin/WeChat/getinfo");//微信授权获取用户信息
+route::rule("wechat_getconfig","admin/WeChat/getConfig");//微信获取页面jssdk配置
+

+ 21 - 12
app/command/companyStats.php

@@ -21,7 +21,7 @@ class companyStats extends Command
 
     protected function execute(Input $input, Output $output)
     {
-      $supplier = ["GS2302231124114965","GS2302231125079621","GS2302231323386950"];
+      $supplier = ["GS2302231124114965","GS2302231125079621","GS2302231323386950",'GS2203161855277894'];
       try{
 	      foreach ($supplier as $sp){
 		      $this->checkData($sp);
@@ -32,7 +32,10 @@ class companyStats extends Command
 
     }
 
-    public function checkData($supplierNo){
+	/**
+	 * @param $supplierNo
+	 */
+    public function checkData($supplierNo):void {
     	$sup =Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$supplierNo])->field("code,name,relation_code")->findOrEmpty();
     	if(empty($sup)) return;
     	$date=date("Y-m-d");
@@ -40,14 +43,13 @@ class companyStats extends Command
     	$temp=[];
 		$total =Db::name("qrd_info")
 		->where(["companyNo"=>$supplierNo,"is_del"=>0,"cxCode"=>""])
-		->whereDay("createdTime","today")
+		->whereDay("createdTime",$date)
 		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
 		$day_thtotal=Db::name("th_source")->alias("a")
 		 ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo")
 		 ->where([['a.th_companyNo',"=",$supplierNo],["b.is_del","=",0]])
-		 ->whereDay("a.createtime","today")->field('sum(a.th_qrd_fee) as th_total')->findOrEmpty();;
-		if(isset($d[1]))Db::name("depart_company")->where($d[1])->save(["sale_total"=>$total['total']??0,
-			"th_total"=>$day_thtotal['th_total']??0]);
+		 ->whereDay("a.createtime",$date)->field('sum(a.th_qrd_fee) as th_total')->findOrEmpty();;
+		if(isset($d[1]))Db::name("depart_company")->where($d[1])->save(["sale_total"=>$total['total']??0,"th_total"=>$day_thtotal['th_total']??0]);
 		else $temp[]=[
 			"companyNo"=>$supplierNo,
 			"companyName"=>$sup['name']??"",
@@ -60,12 +62,12 @@ class companyStats extends Command
 		$total_cx =Db::name("qrd_info")
 		->where(["companyNo"=>$supplierNo,"is_del"=>0])
 		->where("cxCode","<>","")
-		->whereDay("createdTime","today")
+		->whereDay("createdTime",$date)
 		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
 		$day_thtotal_cx=Db::name("th_source")->alias("a")
 		 ->leftJoin("qrd_info b","a.th_qrdNo=b.cxCode")
 		 ->where([['a.th_companyNo',"=",$supplierNo],["b.is_del","=",0]])
-		 ->whereDay("a.createtime","today")
+		 ->whereDay("a.createtime",$date)
 	    ->field("sum(a.th_num*b.goodPrice) as th_total")->findOrEmpty();
 		if(isset($d[2]))Db::name("depart_company")->where($d[2])->save(["sale_total"=>$total_cx['total']??0,
 		"th_total"=>$day_thtotal_cx['th_total']??0]);
@@ -78,7 +80,7 @@ class companyStats extends Command
 			"th_total"=>$day_thtotal_cx['th_total']??0,
 			"addtime"=>date("Y-m-d H:i:s")
 			];
-		$cgd=$this->cgdData($sup['relation_code']);
+		$cgd=$this->cgdData($sup['relation_code'],$date);
 		if(isset($d[3]))Db::name("depart_company")->where($d[3])->save(["sale_total"=>$cgd['cgd_total'],
 		"th_total"=>$cgd['cgd_thtotal']]);
 		else $temp[]=[
@@ -93,16 +95,23 @@ class companyStats extends Command
 		if(!empty($temp))Db::name("depart_company")->insertAll($temp);
 
     }
-    public function cgdData($sup){
+
+	/**
+	 * @param $sup
+	 * @param $date
+	 * @return array
+	 */
+    private function cgdData($sup,$date): array
+    {
 
 		$total =Db::name("cgd_info")
 		->where(["supplierNo"=>$sup,"is_del"=>0,"cxCode"=>""])
-		->whereDay("createdTime","today")
+		->whereDay("createdTime",$date)
 		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
 		$day_thtotal=Db::name("th_source")->alias("a")
 		 ->leftJoin("cgd_info b","(a.th_cgdNo=b.sequenceNo and a.is_th=1) or (a.th_qrdNo=b.cxCode)")
 		 ->where([['b.supplierNo',"=",$sup],["b.is_del","=",0]])
-		 ->whereDay("a.createtime","today")
+		 ->whereDay("a.createtime",$date)
 	    ->field("sum(a.th_num*b.goodPrice) as th_total")->findOrEmpty();
 		return ["cgd_total"=>$total['total']??0,"cgd_thtotal"=>$day_thtotal['th_total']??0];
     }

+ 21 - 10
app/command/stat.php

@@ -19,18 +19,19 @@ class stat extends Command
 	protected function execute(Input $input, Output $output)
 	{
 		// 指令输出
-		$sttime = Cache::get("departTips");
-		if($sttime==1) return '';
-		Cache::set("departTips",1,1800);
+//		$sttime = Cache::get("departTips");
+//		if($sttime==1) return '';
+//		Cache::set("departTips",1,1800);
 		$daprtid = [52,53,56,57];
 		$companyNo='GS2203161855277894' ;
 		$date=date("Y-m-d");
 		$depart= Db::connect("mysql_sys")->name("company_item")->where(["id"=>$daprtid])->column("name","id");
 		$company= Db::connect("mysql_sys")->name("company_info")->where(["companyNo"=>$companyNo])->column("company_name","companyNo");
 		foreach ($depart as $itmeid=>$depart_name){
-			$ist=Db::name("depart_everyday")->where(["depart_id"=>$itmeid,'companyNo'=>$companyNo,"day_time"=>$date])->findOrEmpty();
+			$ist=Db::name("depart_everyday")->where(["depart_id"=>$itmeid,'companyNo'=>$companyNo,"day_time"=>$date])
+			                                ->findOrEmpty();
 			$uidArr =$this->getuid($itmeid);
-			$sale=$this->GetData($uidArr,$companyNo);
+			$sale=$this->GetData($uidArr,$companyNo,$date);
 			if($ist){
 				$ist['sale_total']=$sale['sale_total']??0;
 				$ist['th_total']=$sale['th_total']??0;
@@ -52,22 +53,32 @@ class stat extends Command
 		$output->writeln("[{$date}] 更新数据成功");
 	}
 	//各部门统计数据
-	public  function GetData($uid,$companyNo){
+
+	/**
+	 * @param $uid
+	 * @param $companyNo
+	 * @param $date
+	 * @return array
+	 */
+	public  function GetData($uid,$companyNo,$date):array{
 
 
 		$day_total =Db::name("qrd_info")->where([["ownerid","in",$uid],["is_del","=",0],['companyNo',"=",$companyNo]])
-		                         ->whereDay("createdTime","today")
+		                         ->whereDay("createdTime",$date)
 		              ->sum(Db::raw('totalPrice+th_fee'));
 		$day_thtotal=Db::name("th_source")->alias("a")
 		               ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo or a.th_qrdNo=b.cxCode")
 		               ->where([["b.ownerid","in",$uid],['a.th_companyNo',"=",$companyNo]])
-		               ->whereDay("a.createtime","today")->sum('a.th_qrd_fee');
+		               ->whereDay("a.createtime",$date)->sum('a.th_qrd_fee');
 		return ["sale_total"=>$day_total,"th_total"=>$day_thtotal];
 	}
 
 
-
-	public function getuid($depart_id){
+	/**
+	 * @param $depart_id
+	 * @return array|mixed
+	 */
+	public function getuid($depart_id):array{
 		$uidArr=Cache::get("Depart_Uid_Arr_$depart_id");
 		if($uidArr==false){
 			$uidArr = Db::connect("mysql_sys")->name("account_item")->where(["itemid"=>$depart_id])->column("account_id");

+ 2 - 1
composer.json

@@ -24,7 +24,8 @@
         "topthink/framework": "^6.0.0",
         "topthink/think-orm": "^2.0",
         "topthink/think-multi-app": "^1.0",
-        "phpoffice/phpexcel": "^1.8"
+        "phpoffice/phpexcel": "^1.8",
+        "dodgepudding/wechat-php-sdk": "^1.1"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2",

+ 58 - 1
composer.lock

@@ -4,8 +4,65 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "3aa191934404180c982ae2eea0633938",
+    "content-hash": "ca8f414803112b39761003d8a64f421e",
     "packages": [
+        {
+            "name": "dodgepudding/wechat-php-sdk",
+            "version": "1.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/dodgepudding/wechat-php-sdk.git",
+                "reference": "3a9b9601a07797497e8c428cfd20a29d37a66a35"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/dodgepudding/wechat-php-sdk/zipball/3a9b9601a07797497e8c428cfd20a29d37a66a35",
+                "reference": "3a9b9601a07797497e8c428cfd20a29d37a66a35",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.1.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "dodgepudding\\wechat\\sdk\\": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL"
+            ],
+            "authors": [
+                {
+                    "name": "dodgepudding",
+                    "email": "dodgepudding@gmail.com"
+                },
+                {
+                    "name": "binsee",
+                    "email": "binsee@163.com"
+                }
+            ],
+            "description": "the wechat api library without framework dependency",
+            "keywords": [
+                "sample",
+                "thinkphp",
+                "wechat",
+                "weixin"
+            ],
+            "support": {
+                "issues": "https://github.com/dodgepudding/wechat-php-sdk/issues",
+                "source": "https://github.com/dodgepudding/wechat-php-sdk",
+                "wiki": "https://github.com/dodgepudding/wechat-php-sdk/wiki"
+            },
+            "time": "2015-03-15T17:07:41+00:00"
+        },
         {
             "name": "phpoffice/phpexcel",
             "version": "1.8.2",