Browse Source

添加业绩

shish 5 years ago
parent
commit
e22e0d9b33

+ 480 - 478
app/ghs/controllers/OrderController.php

@@ -26,149 +26,158 @@ use common\components\stringUtil;
 
 class OrderController extends BaseController
 {
-	
-	public $guestAccessAction = ['create-order', 'order-relate', 'fast-pay'];
-	
-	//订单列表 shish 2021.1.20
-	public function actionList()
-	{
-		$get = Yii::$app->request->get();
-		$status = $get['status'] ?? 0;
-		if (!empty($status)) {
-			$where['status'] = $status;
-		}
-		$where['merchantId'] = $this->sjId;
-		if (isset($get['shopId'])) {
-			$shopId = $get['shopId'] ?? 0;
-			if (!empty($shopId)) {
-				$where['shopId'] = $this->shopId;
-			}
-		} else {
-			$where['shopId'] = $this->shopId;
-		}
-		$searchTime = $get['searchTime'] ?? '';
-		if (!empty($searchTime)) {
-			$startTime = $get['startTime'] ?? '';
-			$endTime = $get['endTime'] ?? '';
-			$period = dateUtil::formatTime($searchTime, $startTime, $endTime);
-			$where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
-		}
-		
-		$data = OrderClass::getOrderList($where);
-		util::success($data);
-	}
-	
-	//商城下单操作 shish 2021.1.14
-	public function actionCreateOrder()
-	{
-		$post = Yii::$app->request->post();
-		$adminId = $this->adminId;
-		$shopId = $this->shopId;
-		$customId = $post['customId'] ?? 0;
-		if (!empty($shopId)) {
-			//供货商 员工 开单
-			$post['customId'] = $customId;
-			$post['adminId'] = $adminId;
-			$post['shopId'] = $shopId;
-		} else {
-			//供货商 商城 客户 开单
-			$post['adminId'] = $adminId;
-			$shopId = $post['shopId'] ?? 0;
-			if (empty($shopId)) {
-				util::fail('请选择供货商');
-			}
-			$post['shopId'] = $shopId;
-			$shop = ShopClass::getById($shopId);
-			if (empty($shop)) {
-				util::fail('没有找到供货商');
-			}
-		}
-		
-		$post['payWay'] = $this->isWx == true ? 0 : 1;
-		$post['merchantId'] = $this->sjId;
-		$post['fromType'] = 1;//商城
-		$post['prePrice'] = 0.01;
-		$post['actPrice'] = 0.01;
-		$post['sendSide'] = $post['sendSide'] ?? 0;
-		
-		$productJson = $post['product'] ?? '';
-		if (empty($productJson)) {
-			util::fail('请选择花材');
-		}
-		$productList = json_decode($productJson, true);
-		if (empty($productList)) {
-			util::fail('请选择花材');
-		}
-		$orderSn = '';
-		$id = 0;
-		$connection = Yii::$app->db;//事务处理
-		$transaction = $connection->beginTransaction();
-		try {
-			//判断花材有效性
-			ProductClass::valid($productList, $this->shopId);
-			$post['product'] = $productList;
-			$order = OrderClass::addOrder($post);
-			$orderSn = $order['orderSn'] ?? '';
-			$id = $order['id'] ?? 0;
-			$transaction->commit();
-		} catch (\Exception $e) {
-			$transaction->rollBack();
-			Yii::info("下单报错:" . $e->getMessage());
-			util::fail('下单失败');
-		}
-		
-		util::success([
-			'orderId' => $id,
-			'orderSn' => $orderSn,
-			'totalPrice' => 0.01,
-			'sendType' => '快递送',
-			'sendTime' => '15:00',
-			'qrCode' => imgUtil::getPrefix() . '/hhb_small.png',
-		]);
-	}
-	
-	//延期支付 shish 2021.1.19
-	public function actionDebt()
-	{
-		$get = Yii::$app->request->get();
-		$id = $get['id'] ?? 0;
-		$info = OrderClass::getOrderInfo($id);
-		OrderClass::valid($info, $this->shopId);
-		OrderClass::debt($info, $this->shop);
-		util::complete();
-	}
-	
-	//已经支付
-	public function actionHasPay()
-	{
-		$get = Yii::$app->request->get();
-		$id = $get['id'] ?? 0;
-		$info = OrderClass::getOrderInfo($id);
-		OrderClass::valid($info, $this->shopId);
-		OrderClass::payOk($info, 2);
-		util::complete();
-	}
-	
-	//获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
-	public function actionWxPay()
-	{
-		ini_set('date.timezone', 'Asia/Shanghai');
-		$post = Yii::$app->request->post();
-		$couponId = $post['couponId'] ?? 0;
-		$orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
-		$order = OrderClass::getByOrderSn($orderSn);
-		if (empty($order)) {
-			util::fail('订单号无效');
-		}
-		$id = $order['id'];
-		
-		//支付前验证订单有效性
-		if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
-			util::fail('没有权限操作');
-		}
-		
-		$name = $order['orderName'] ?? '购买商品';
-		$totalFee = $order['actPrice'];
+
+    public $guestAccessAction = ['create-order', 'order-relate', 'fast-pay'];
+
+    //订单列表 shish 2021.1.20
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $status = $get['status'] ?? 0;
+        if (!empty($status)) {
+            $where['status'] = $status;
+        }
+        $where['merchantId'] = $this->sjId;
+        if (isset($get['shopId'])) {
+            $shopId = $get['shopId'] ?? 0;
+            if (!empty($shopId)) {
+                $where['shopId'] = $this->shopId;
+            }
+        } else {
+            $where['shopId'] = $this->shopId;
+        }
+        $searchTime = $get['searchTime'] ?? '';
+        if (!empty($searchTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
+            $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
+
+        $data = OrderClass::getOrderList($where);
+        util::success($data);
+    }
+
+    //商城下单操作 shish 2021.1.14
+    public function actionCreateOrder()
+    {
+        $post = Yii::$app->request->post();
+        $adminId = $this->adminId;
+        $shopId = $this->shopId;
+        $customId = $post['customId'] ?? 0;
+        if (!empty($shopId)) {
+            //供货商 员工 开单
+            $post['customId'] = $customId;
+            $post['adminId'] = $adminId;
+            $post['shopId'] = $shopId;
+        } else {
+            //供货商 商城 客户 开单
+            $post['adminId'] = $adminId;
+            $shopId = $post['shopId'] ?? 0;
+            if (empty($shopId)) {
+                util::fail('请选择供货商');
+            }
+            $post['shopId'] = $shopId;
+            $shop = ShopClass::getById($shopId);
+            if (empty($shop)) {
+                util::fail('没有找到供货商');
+            }
+        }
+
+        $post['payWay'] = $this->isWx == true ? 0 : 1;
+        $post['merchantId'] = $this->sjId;
+        $post['fromType'] = 1;//商城
+        $post['prePrice'] = 0.01;
+        $post['actPrice'] = 0.01;
+        $post['sendSide'] = $post['sendSide'] ?? 0;
+
+        $productJson = $post['product'] ?? '';
+        if (empty($productJson)) {
+            util::fail('请选择花材');
+        }
+        $productList = json_decode($productJson, true);
+        if (empty($productList)) {
+            util::fail('请选择花材');
+        }
+        $orderSn = '';
+        $id = 0;
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            //判断花材有效性
+            ProductClass::valid($productList, $this->shopId);
+            $post['product'] = $productList;
+            $order = OrderClass::addOrder($post);
+            $orderSn = $order['orderSn'] ?? '';
+            $id = $order['id'] ?? 0;
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("下单报错:" . $e->getMessage());
+            util::fail('下单失败');
+        }
+
+        util::success([
+            'orderId' => $id,
+            'orderSn' => $orderSn,
+            'totalPrice' => 0.01,
+            'sendType' => '快递送',
+            'sendTime' => '15:00',
+            'qrCode' => imgUtil::getPrefix() . '/hhb_small.png',
+        ]);
+    }
+
+    //延期支付 shish 2021.1.19
+    public function actionDebt()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $info = OrderClass::getOrderInfo($id);
+        OrderClass::valid($info, $this->shopId);
+        OrderClass::debt($info, $this->shop);
+        util::complete();
+    }
+
+    //已收款 shish 2021.3.15
+    public function actionHasPay()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $info = OrderClass::getOrderInfo($id);
+        OrderClass::valid($info, $this->shopId);
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            OrderClass::payOk($info, 2);
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("已收款操作报错:" . $e->getMessage());
+            util::fail('操作失败');
+        }
+        util::complete();
+    }
+
+    //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
+    public function actionWxPay()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $post = Yii::$app->request->post();
+        $couponId = $post['couponId'] ?? 0;
+        $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
+        $order = OrderClass::getByOrderSn($orderSn);
+        if (empty($order)) {
+            util::fail('订单号无效');
+        }
+        $id = $order['id'];
+
+        //支付前验证订单有效性
+        if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
+            util::fail('没有权限操作');
+        }
+
+        $name = $order['orderName'] ?? '购买商品';
+        $totalFee = $order['actPrice'];
 
 
 //        if (httpUtil::isMiniProgram()) {
@@ -176,343 +185,336 @@ class OrderController extends BaseController
 //        } else {
 //            $openId = $this->admin['openId'];
 //        }
-		
-		//强制使用小程序的miniOpenId
-		$openId = $this->admin['miniOpenId'];
-		
-		$typeList = configDict::getConfig('capitalType');
-		$capitalType = $typeList['xhGhsOrder']['id'];
-		//流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
-		$wxPayType = 0;
-		if (httpUtil::isMiniProgram()) {
-			$wxPayType = 1;
-		}
-		$attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
-		//订单30分钟后过期
-		$now = time();
-		$expireTime = $now + 1800;
-		
-		$wx = Yii::getAlias("@vendor/weixin");
-		require_once($wx . '/lib/WxPay.Api.php');
-		require_once($wx . '/example/WxPay.JsApiPay.php');
-		$input = new \WxPayUnifiedOrder();
-		$input->SetBody($name);
-		$input->SetOut_trade_no($orderSn);
-		$input->SetTotal_fee($totalFee * 100);
-		$input->SetTime_start(date("YmdHis", $now));
-		$input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
-		$input->SetTime_expire(date("YmdHis", $expireTime));
-		$input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
-		$input->SetTrade_type("JSAPI");
-		
-		//花卉宝代为申请的微信支付
-		//$merchantExtend = $this->sjExtend;
-		$merchantExtend = WxOpenClass::getGhsWxInfo();
-		if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
-			$input->SetSub_openid($openId);
-		} else {
-			$input->SetOpenid($openId);
-		}
+
+        //强制使用小程序的miniOpenId
+        $openId = $this->admin['miniOpenId'];
+
+        $typeList = configDict::getConfig('capitalType');
+        $capitalType = $typeList['xhGhsOrder']['id'];
+        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+        $wxPayType = 0;
+        if (httpUtil::isMiniProgram()) {
+            $wxPayType = 1;
+        }
+        $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
+        //订单30分钟后过期
+        $now = time();
+        $expireTime = $now + 1800;
+
+        $wx = Yii::getAlias("@vendor/weixin");
+        require_once($wx . '/lib/WxPay.Api.php');
+        require_once($wx . '/example/WxPay.JsApiPay.php');
+        $input = new \WxPayUnifiedOrder();
+        $input->SetBody($name);
+        $input->SetOut_trade_no($orderSn);
+        $input->SetTotal_fee($totalFee * 100);
+        $input->SetTime_start(date("YmdHis", $now));
+        $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
+        $input->SetTime_expire(date("YmdHis", $expireTime));
+        $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
+        $input->SetTrade_type("JSAPI");
+
+        //花卉宝代为申请的微信支付
+        //$merchantExtend = $this->sjExtend;
+        $merchantExtend = WxOpenClass::getGhsWxInfo();
+        if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
+            $input->SetSub_openid($openId);
+        } else {
+            $input->SetOpenid($openId);
+        }
 
 //        if (httpUtil::isMiniProgram()) {
 //            $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
 //        }
-		
-		//强制使用小程序的miniAppId
-		$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-		
-		$wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-		$tools = new \JsApiPay();
-		$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-		$newParams = json_decode($jsApiParameters, true);
-		//微信不能修改价格
-		$current = date("Y-m-d H:i:s");
-		$updateData = ['deadline' => $current, 'modPrice' => 0];
-		OrderClass::updateById($id, $updateData);
-		util::success($newParams);
-	}
-	
-	//获取订单详情 shish 2021.1.21
-	public function actionDetail()
-	{
-		$get = Yii::$app->request->get();
-		$id = $get['id'] ?? 0;
-		$info = OrderClass::getOrderInfo($id, true, true, true, true, false);
-		OrderClass::valid($info, $this->shopId);
-		util::success($info);
-	}
-	
-	//自取和免发货流程处理 shish 2021.1.22
-	public function actionWithoutSend()
-	{
-		$get = Yii::$app->request->get();
-		$id = $get['id'] ?? 0;
-		$info = OrderClass::getOrderInfo($id);
-		OrderClass::valid($info, $this->shopId);
-		OrderClass::withoutSend($info);
-		util::complete();
-	}
-	
-	//本店送 shish 2021.1.24
-	public function actionSelfSend()
-	{
-		$get = Yii::$app->request->get();
-		$id = isset($get['id']) ? $get['id'] : 0;
-		$info = OrderClass::getOrderInfo($id);
-		OrderClass::valid($info, $this->shopId);
-		$connection = Yii::$app->db;
-		$transaction = $connection->beginTransaction();
-		try {
-			OrderClass::selfSend($info);
-			$transaction->commit();
-		} catch (\Exception $exception) {
-			$transaction->rollBack();
-			Yii::info("本店送操作报错:" . $exception->getMessage());
-			util::fail('操作失败');
-		}
-		util::complete();
-	}
-	
-	//运费计算 shish 2021.1.24
-	public function actionFreight()
-	{
-		util::success(['sndCost' => 20]);
-	}
-	
-	//发快递和第三方配送 shish 2021.1.24
-	public function actionThirdSend()
-	{
-		$respond = [
-			'sendSide' => '达达',
-			'distance' => 5.5,
-			'sendCost' => 20,
-			'status' => 1,
-			'tip' => 5,
-		];
-		util::success($respond);
-	}
-	
-	//确认送达 shish 2021.1.24
-	public function actionReach()
-	{
-		$get = Yii::$app->request->get();
-		$id = isset($get['id']) ? $get['id'] : 0;
-		$info = OrderClass::getOrderInfo($id);
-		OrderClass::valid($info, $this->shopId);
-		$connection = Yii::$app->db;
-		$transaction = $connection->beginTransaction();
-		try {
-			OrderClass::reach($info);
-			$transaction->commit();
-		} catch (\Exception $exception) {
-			$transaction->rollBack();
-			Yii::info("送达操作报错:" . $exception->getMessage());
-			util::fail('操作失败');
-		}
-		util::complete();
-	}
-	
-	//快捷付款订单
-	public function actionFastPay()
-	{
-		ini_set('date.timezone', 'Asia/Shanghai');
-		$post = Yii::$app->request->post();
-		$payWay = isset($post['payWay']) ? $post['payWay'] : 0;
-		$post['shopId'] = 2;
-		//默认门店订单
-		$store = isset($post['store']) ? $post['store'] : 1;
-		$post['store'] = $store;
-		$fromType = $post['fromType'] ?? 1;
-		$post['userId'] = $this->adminId;
-		$admin = $this->admin;
-		$post['bookName'] = isset($admin['adminName']) ? $admin['adminName'] : '';
-		$bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
-		$bookMobile = empty($bookMobile) && isset($admin['mobile']) && !empty($admin['mobile']) ? $admin['mobile'] : $bookMobile;
-		$post['bookMobile'] = $bookMobile;
-		$prePrice = round($post['prePrice'], 2);
-		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-		$sourceType = 0;
-		$discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
-		$actPrice = $discountData['price'];
-		$post['discountType'] = $discountData['discountType'];
-		$post['discountAmount'] = $discountData['discountAmount'];
-		$post['actPrice'] = $actPrice;
-		$post['payStyle'] = 0;
-		$post['merchantId'] = $this->sjId;
-		$now = time();
-		//订单5分钟后过期
-		$expireTime = $now + 300;
-		$post['createTime'] = date("Y-m-d H:i:s", $now);
-		$post['deadline'] = $expireTime;
-		if ($actPrice <= 0) {
-			util::fail('请填写正确的金额');
-		}
-		//微信支付订单提交不能修改价格
-		$post['modPrice'] = $this->isWx ? 0 : 1;
-		$post['sourceType'] = $sourceType;
-		$post['goodsNum'] = 1;
-		$post['fromType'] = $fromType;
-		$post['product'] = [];
-		$order = OrderClass::addOrder($post);
-		$id = $order['id'];
-		$orderSn = $order['orderSn'];
-		$merchantId = $this->sjId;
-		if ($payWay == 0) {
-			$id = $order['id'];
-			$name = '购买商品';
-			$totalFee = $actPrice;
-			$admin = AdminClass::getAdminById($this->adminId);
-			$openId = isset($admin['openId']) ? $admin['openId'] : 0;
-			if (httpUtil::isMiniProgram()) {
-				//小程序使用miniOpenId
-				$openId = $admin['miniOpenId'];
-			} else {
-				//util::fail('仅支持小程序支付');
-				$openId = $admin['miniOpenId'];
-			}
-			$typeList = configDict::getConfig('capitalType');
-			$capitalType = $typeList['xhGhsOrder']['id'];
-			//流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
-			$wxPayType = 0;
-			if (httpUtil::isMiniProgram()) {
-				$wxPayType = 1;
-			}
-			$attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
-			$wx = Yii::getAlias("@vendor/weixin");
-			require_once($wx . '/lib/WxPay.Api.php');
-			require_once($wx . '/example/WxPay.JsApiPay.php');
-			$input = new \WxPayUnifiedOrder();
-			$input->SetBody($name);
-			$input->SetOut_trade_no($orderSn);
-			$input->SetTotal_fee($totalFee * 100);
-			$input->SetTime_start(date("YmdHis", $now));
-			$input->SetAttach($attach);
-			//设置订单有效期5分钟
-			$input->SetTime_expire(date("YmdHis", $expireTime));
-			$input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
-			$input->SetTrade_type("JSAPI");
-			
-			//花卉宝代为申请的微信支付
-			//$merchantExtend = $this->sjExtend;
-			$merchantExtend = WxOpenClass::getGhsWxInfo();
-			if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
-				$input->SetSub_openid($openId);
-			} else {
-				$input->SetOpenid($openId);
-			}
-			//小程序使用miniAppId
-			if (httpUtil::isMiniProgram()) {
-				$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-			}
-			//强制使用小程序的appId
-			$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-			Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
-			$wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-			$tools = new \JsApiPay();
-			$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-			$newParams = json_decode($jsApiParameters, true);
-			$newParams['orderId'] = $id;
-			util::success($newParams);
-		} elseif ($payWay == 1) {
-			$extend = MerchantExtendService::getByMerchantId($merchantId);
-			if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
-				util::fail('支付宝付款即将开通...');
-			}
-			$config = [
-				//应用ID,您的APPID。
-				'app_id' => $extend['alipayPId'],
-				//商户私钥,您的原始格式RSA私钥
-				'merchant_private_key' => $extend['alipayKey'],
-				//异步通知地址
-				'notify_url' => Yii::$app->params['ghsHost'] . "/notice/alipay-callback",
-				//同步跳转
-				'return_url' => "",
-				//编码格式
-				'charset' => "UTF-8",
-				//签名方式
-				'sign_type' => "RSA2",
-				//支付宝网关
-				'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
-				//支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
-				'alipay_public_key' => $extend['alipayPublicKey'],
-			];
-			
-			Yii::info(json_encode($config) . ' aplipay config');
-			
-			$alipayWap = Yii::getAlias("@vendor/alipayWap");
-			require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
-			require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
-			
-			$totalFee = $order['actPrice'];
-			$out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
-			$subject = '购买商品';//订单名称,必填
-			$total_amount = $totalFee;//付款金额,必填
-			$body = '';//商品描述,可空
-			$timeout_express = "1m";//超时时间
-			
-			$typeList = configDict::getConfig('capitalType');
-			$capitalType = $typeList['xhGhsOrder']['id'];
-			$passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
-			$passbackParams = urlencode($passbackParams);
-			
-			$payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
-			$payRequestBuilder->setBody($body);
-			$payRequestBuilder->setSubject($subject);
-			$payRequestBuilder->setOutTradeNo($out_trade_no);
-			$payRequestBuilder->setTotalAmount($total_amount);
-			$payRequestBuilder->setTimeExpress($timeout_express);
-			//在异步通知时将该参数原样返回
-			$payRequestBuilder->setPassbackParams($passbackParams);
-			//同步通知
-			$returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
-			//异步通知
-			$notifyUrl = Yii::$app->params['ghsHost'] . "/notice/alipay-callback";
-			$payResponse = new \AlipayTradeService($config);
-			$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
-			//直接将支付宝的html返回给前端
-			echo $result;
-		} elseif ($payWay == 2) {
-			//余额支付,验证支付密码是否正确
-			$payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
-			$typeList = configDict::getConfig('capitalType');
-			$capitalType = $typeList['xhGhsOrder']['id'];
-			$callbackParams = [];
-			$respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
-			$balance = isset($respond['balance']) ? $respond['balance'] : 0;
-			util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $id, 'balance' => $balance]);
-		} else {
-			util::fail('无效的支付方式');
-		}
-	}
-	
-	//下单要用到的相关信息 shish 2019.12.6
-	public function actionOrderRelate()
-	{
-		$regionTree = RegionService::tree();
-		$shop = ShopService::getDefaultShop($this->sj);
-		$freight = ['first' => 5, 'add' => 2];
-		$mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-		$out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
-		util::success($out);
-	}
-	
-	//客户欠款的订单 shish 2021.2.4
-	public function actionDebtList()
-	{
-		$id = Yii::$app->request->get('id', 0);
-		$info = CustomClass::getCustom($id);
-		CustomClass::valid($info, $this->sjId);
-		$where = ['customId' => $id, 'debt' => 1];
-		$respond = OrderService::getDebtOrderList($where);
-		$respond['customInfo'] = $info;
-		util::success($respond);
-	}
-	
-	//收款 shish 2021.2.4
-	public function actionClearDebt()
-	{
-		$ids = Yii::$app->request->post('id');
-		util::complete();
-	}
-	
+
+        //强制使用小程序的miniAppId
+        $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+
+        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+        $tools = new \JsApiPay();
+        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+        $newParams = json_decode($jsApiParameters, true);
+        //微信不能修改价格
+        $current = date("Y-m-d H:i:s");
+        $updateData = ['deadline' => $current, 'modPrice' => 0];
+        OrderClass::updateById($id, $updateData);
+        util::success($newParams);
+    }
+
+    //获取订单详情 shish 2021.1.21
+    public function actionDetail()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $info = OrderClass::getOrderInfo($id, true, true, true, true, false);
+        OrderClass::valid($info, $this->shopId);
+        util::success($info);
+    }
+
+    //自取和免发货流程处理 shish 2021.1.22
+    public function actionWithoutSend()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $info = OrderClass::getOrderInfo($id);
+        OrderClass::valid($info, $this->shopId);
+        OrderClass::withoutSend($info);
+        util::complete();
+    }
+
+    //本店送 shish 2021.1.24
+    public function actionSelfSend()
+    {
+        $get = Yii::$app->request->get();
+        $id = isset($get['id']) ? $get['id'] : 0;
+        $info = OrderClass::getOrderInfo($id);
+        OrderClass::valid($info, $this->shopId);
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            OrderClass::selfSend($info);
+            $transaction->commit();
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("本店送操作报错:" . $exception->getMessage());
+            util::fail('操作失败');
+        }
+        util::complete();
+    }
+
+    //运费计算 shish 2021.1.24
+    public function actionFreight()
+    {
+        util::success(['sndCost' => 20]);
+    }
+
+    //发快递和第三方配送 shish 2021.1.24
+    public function actionThirdSend()
+    {
+        $respond = [
+            'sendSide' => '达达',
+            'distance' => 5.5,
+            'sendCost' => 20,
+            'status' => 1,
+            'tip' => 5,
+        ];
+        util::success($respond);
+    }
+
+    //确认送达 shish 2021.1.24
+    public function actionReach()
+    {
+        $get = Yii::$app->request->get();
+        $id = isset($get['id']) ? $get['id'] : 0;
+        $info = OrderClass::getOrderInfo($id);
+        OrderClass::valid($info, $this->shopId);
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            OrderClass::reach($info);
+            $transaction->commit();
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("送达操作报错:" . $exception->getMessage());
+            util::fail('操作失败');
+        }
+        util::complete();
+    }
+
+    //快捷付款订单
+    public function actionFastPay()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $post = Yii::$app->request->post();
+        $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
+        $post['shopId'] = 2;
+        //默认门店订单
+        $store = isset($post['store']) ? $post['store'] : 1;
+        $post['store'] = $store;
+        $fromType = $post['fromType'] ?? 1;
+        $post['userId'] = $this->adminId;
+        $admin = $this->admin;
+        $post['bookName'] = isset($admin['adminName']) ? $admin['adminName'] : '';
+        $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
+        $bookMobile = empty($bookMobile) && isset($admin['mobile']) && !empty($admin['mobile']) ? $admin['mobile'] : $bookMobile;
+        $post['bookMobile'] = $bookMobile;
+        $prePrice = round($post['prePrice'], 2);
+        $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
+        $sourceType = 0;
+        $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+        $actPrice = $discountData['price'];
+        $post['discountType'] = $discountData['discountType'];
+        $post['discountAmount'] = $discountData['discountAmount'];
+        $post['actPrice'] = $actPrice;
+        $post['payStyle'] = 0;
+        $post['merchantId'] = $this->sjId;
+        $now = time();
+        //订单5分钟后过期
+        $expireTime = $now + 300;
+        $post['createTime'] = date("Y-m-d H:i:s", $now);
+        $post['deadline'] = $expireTime;
+        if ($actPrice <= 0) {
+            util::fail('请填写正确的金额');
+        }
+        //微信支付订单提交不能修改价格
+        $post['modPrice'] = $this->isWx ? 0 : 1;
+        $post['sourceType'] = $sourceType;
+        $post['goodsNum'] = 1;
+        $post['fromType'] = $fromType;
+        $post['product'] = [];
+        $order = OrderClass::addOrder($post);
+        $id = $order['id'];
+        $orderSn = $order['orderSn'];
+        $merchantId = $this->sjId;
+        if ($payWay == 0) {
+            $id = $order['id'];
+            $name = '购买商品';
+            $totalFee = $actPrice;
+            $admin = AdminClass::getAdminById($this->adminId);
+            $openId = isset($admin['openId']) ? $admin['openId'] : 0;
+            if (httpUtil::isMiniProgram()) {
+                //小程序使用miniOpenId
+                $openId = $admin['miniOpenId'];
+            } else {
+                //util::fail('仅支持小程序支付');
+                $openId = $admin['miniOpenId'];
+            }
+            $typeList = configDict::getConfig('capitalType');
+            $capitalType = $typeList['xhGhsOrder']['id'];
+            //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+            $wxPayType = 0;
+            if (httpUtil::isMiniProgram()) {
+                $wxPayType = 1;
+            }
+            $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
+            $wx = Yii::getAlias("@vendor/weixin");
+            require_once($wx . '/lib/WxPay.Api.php');
+            require_once($wx . '/example/WxPay.JsApiPay.php');
+            $input = new \WxPayUnifiedOrder();
+            $input->SetBody($name);
+            $input->SetOut_trade_no($orderSn);
+            $input->SetTotal_fee($totalFee * 100);
+            $input->SetTime_start(date("YmdHis", $now));
+            $input->SetAttach($attach);
+            //设置订单有效期5分钟
+            $input->SetTime_expire(date("YmdHis", $expireTime));
+            $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
+            $input->SetTrade_type("JSAPI");
+
+            //花卉宝代为申请的微信支付
+            //$merchantExtend = $this->sjExtend;
+            $merchantExtend = WxOpenClass::getGhsWxInfo();
+            if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
+                $input->SetSub_openid($openId);
+            } else {
+                $input->SetOpenid($openId);
+            }
+            //小程序使用miniAppId
+            if (httpUtil::isMiniProgram()) {
+                $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+            }
+            //强制使用小程序的appId
+            $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+            Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
+            $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+            $tools = new \JsApiPay();
+            $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+            $newParams = json_decode($jsApiParameters, true);
+            $newParams['orderId'] = $id;
+            util::success($newParams);
+        } elseif ($payWay == 1) {
+            $extend = MerchantExtendService::getByMerchantId($merchantId);
+            if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
+                util::fail('支付宝付款即将开通...');
+            }
+            $config = [
+                //应用ID,您的APPID。
+                'app_id' => $extend['alipayPId'],
+                //商户私钥,您的原始格式RSA私钥
+                'merchant_private_key' => $extend['alipayKey'],
+                //异步通知地址
+                'notify_url' => Yii::$app->params['ghsHost'] . "/notice/alipay-callback",
+                //同步跳转
+                'return_url' => "",
+                //编码格式
+                'charset' => "UTF-8",
+                //签名方式
+                'sign_type' => "RSA2",
+                //支付宝网关
+                'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
+                //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
+                'alipay_public_key' => $extend['alipayPublicKey'],
+            ];
+
+            Yii::info(json_encode($config) . ' aplipay config');
+
+            $alipayWap = Yii::getAlias("@vendor/alipayWap");
+            require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
+            require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
+
+            $totalFee = $order['actPrice'];
+            $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
+            $subject = '购买商品';//订单名称,必填
+            $total_amount = $totalFee;//付款金额,必填
+            $body = '';//商品描述,可空
+            $timeout_express = "1m";//超时时间
+
+            $typeList = configDict::getConfig('capitalType');
+            $capitalType = $typeList['xhGhsOrder']['id'];
+            $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
+            $passbackParams = urlencode($passbackParams);
+
+            $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
+            $payRequestBuilder->setBody($body);
+            $payRequestBuilder->setSubject($subject);
+            $payRequestBuilder->setOutTradeNo($out_trade_no);
+            $payRequestBuilder->setTotalAmount($total_amount);
+            $payRequestBuilder->setTimeExpress($timeout_express);
+            //在异步通知时将该参数原样返回
+            $payRequestBuilder->setPassbackParams($passbackParams);
+            //同步通知
+            $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
+            //异步通知
+            $notifyUrl = Yii::$app->params['ghsHost'] . "/notice/alipay-callback";
+            $payResponse = new \AlipayTradeService($config);
+            $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
+            //直接将支付宝的html返回给前端
+            echo $result;
+        } elseif ($payWay == 2) {
+            //余额支付,验证支付密码是否正确
+            $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
+            $typeList = configDict::getConfig('capitalType');
+            $capitalType = $typeList['xhGhsOrder']['id'];
+            $callbackParams = [];
+            $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
+            $balance = isset($respond['balance']) ? $respond['balance'] : 0;
+            util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $id, 'balance' => $balance]);
+        } else {
+            util::fail('无效的支付方式');
+        }
+    }
+
+    //下单要用到的相关信息 shish 2019.12.6
+    public function actionOrderRelate()
+    {
+        $regionTree = RegionService::tree();
+        $shop = ShopService::getDefaultShop($this->sj);
+        $freight = ['first' => 5, 'add' => 2];
+        $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
+        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
+        util::success($out);
+    }
+
+    //客户欠款的订单 shish 2021.2.4
+    public function actionDebtList()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $info = CustomClass::getCustom($id);
+        CustomClass::valid($info, $this->sjId);
+        $where = ['customId' => $id, 'debt' => 1];
+        $respond = OrderService::getDebtOrderList($where);
+        $respond['customInfo'] = $info;
+        util::success($respond);
+    }
+
 }

+ 394 - 391
biz-ghs/order/classes/OrderClass.php

@@ -7,6 +7,7 @@ use biz\sj\classes\MerchantAssetClass;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\stat\classes\StatOrderCountClass;
+use bizGhs\stat\classes\StatYjClass;
 use common\components\orderSn;
 use common\components\stringUtil;
 use common\components\util;
@@ -15,395 +16,397 @@ use bizGhs\base\classes\BaseClass;
 
 class OrderClass extends BaseClass
 {
-	
-	public static $baseFile = '\bizGhs\order\models\Order';
-	
-	//已退款
-	const ORDER_STATUS_REFUND = 6;
-	//已取消
-	const ORDER_STATUS_CANCEL = 5;
-	//已完成
-	const ORDER_STATUS_COMPLETE = 4;
-	//配送中
-	const ORDER_STATUS_SENDING = 3;
-	//待配送
-	const ORDER_STATUS_UN_SEND = 2;
-	//待付款,待确认
-	const ORDER_STATUS_UN_PAY = 1;
-	
-	//未确认
-	const SEND_TYPE_UNKNOWN = 1;
-	//自取
-	const SEND_TYPE_NO = 2;
-	//自己送
-	const SEND_TYPE_MYSELF = 3;
-	//快递送
-	const SEND_TYPE_THIRD = 4;
-	
-	//待付款,待确认
-	const PAY_STATUS_UN_PAY = 1;
-	//已付款
-	const PAY_STATUS_HAS_PAY = 2;
-	
-	//待配送
-	const SEND_STATUS_UN_SEND = 1;
-	//配送中
-	const SEND_STATUS_SENDING = 2;
-	//配送完成
-	const SEND_STATUS_COMPLETE = 3;
-	
-	//订单总流程数
-	const TOTAL_FLOW = 3;
-	
-	//添加订单 shish 2019.12.5
-	public static function addOrder($data)
-	{
-		$merchantId = $data['merchantId'] ?? 0;
-		$month = date("Ym");
-		$orderSn = orderSn::getGhsOrderSn();
-		$data['orderSn'] = $orderSn;
-		$data['payStatus'] = self::PAY_STATUS_UN_PAY;
-		
-		//花材列表
-		$product = $data['product'];
-		OrderItemClass::replace(['orderSn' => $orderSn], $product, true);
-		
-		//将花店每月的总订单数作为编号
-		$riseNum = StatOrderCountClass::addOrder($month, $merchantId);
-		$data['sendNum'] = $riseNum;
-		$data['num'] = 1;
-		$data['smallNum'] = 1;
-		$data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
-		//订单30分钟后过期
-		$data['deadline'] = date("Y-m-d H:i:s", (time() + 1800));
-		$data['sendCost'] = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
-		$return = self::add($data);
-		$orderId = $return['id'];
-		
-		//全部订单+1,待付款订单+1
-		$merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
-		$merchantAsset->unPayOrder += 1;
-		$merchantAsset->totalOrder += 1;
-		$merchantAsset->save();
-		
-		//增加下单流程
-		$payTime = date("Y-m-d H:i:s");
-		$sendData = ['orderId' => $orderId, 'orderSn' => $orderSn, 'payTime' => $payTime];
-		OrderSendClass::placeOrder($sendData);
-		
-		//扣库存 2021.2.23 linqh
-		foreach ($product as $key => $val) {
-			ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum']);
-		}
-		return $return;
-	}
-	
-	//根据订单编号查询 shish 2021.19
-	public static function getByOrderSn($orderSn)
-	{
-		return self::getByCondition(['orderSn' => $orderSn]);
-	}
-	
-	//订单列表 shish 2021.1.19
-	public static function getOrderList($where)
-	{
-		$data = self::getList('*', $where, 'addTime DESC');
-		$data['list'] = self::groupOrder($data['list'], true, false, false, false, true);
-		$data['allNum'] = 0;
-		$data['unPayNum'] = 0;
-		$data['unSendNum'] = 0;
-		$data['sendingNum'] = 0;
-		$data['finishNum'] = 0;
-		return $data;
-	}
-	
-	//显示操作按钮
-	public static function getShowButton($showButton, $isList, $order)
-	{
-		if ($showButton == false) {
-			return [];
-		}
-		//列表页显示的按钮
-		if ($isList) {
-			$item = ['type' => 'item', 'show' => 1, 'disable' => 1];
-			$send = ['type' => 'send', 'show' => 1, 'disable' => 0];
-			$selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
-			if (in_array($order['status'], [self::ORDER_STATUS_UN_PAY, self::ORDER_STATUS_UN_SEND])) {
-				//待付款和待配送订单,改花材按钮才能点击
-				$item['disable'] = 0;
-			}
-			if ($order['sendType'] == self::SEND_TYPE_NO) {
-				//自取订单,发货按钮不可点
-				$send['disable'] = 1;
-			}
-			if ($order['sendType'] == self::SEND_TYPE_UNKNOWN) {
-				//只有未确认配送方式的订单才可点击自取
-				$selfGet['disable'] = 0;
-			}
-			return [$item, $send, $selfGet];
-		}
-		
-		//待确认订单显示延期付和已付款
-		if ($order['status'] == OrderClass::ORDER_STATUS_UN_PAY) {
-			$debtPay = ['type' => 'debtPay', 'show' => 1, 'disable' => 0];
-			$hasPay = ['type' => 'hasPay', 'show' => 1, 'disable' => 0];
-			return [$debtPay, $hasPay];
-		}
-		
-		//待配送订单显示打印、发货和自取
-		if ($order['status'] == OrderClass::ORDER_STATUS_UN_SEND) {
-			//没有花材的订单按钮全部置灰色不可点
-			$print = ['type' => 'print', 'show' => 0, 'disable' => 1];
-			$item = ['type' => 'item', 'show' => 1, 'disable' => 1];
-			$selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
-			$send = ['type' => 'send', 'show' => 1, 'disable' => 1];
-			if ($order['hasItem'] == 2) {
-				return [$print, $item, $selfGet, $send];
-			}
-			$print['disable'] = 0;
-			$selfGet['disable'] = 0;
-			$send['disable'] = 0;
-			$item['disable'] = 0;
-			return [$print, $item, $selfGet, $send];
-		}
-		//配送中显示按钮
-		if ($order['status'] == OrderClass::ORDER_STATUS_SENDING) {
-			$print = ['type' => 'print', 'show' => 1, 'disable' => 1];
-			$send = ['type' => 'send', 'show' => 1, 'disable' => 1];
-			return [$print, $send];
-		}
-		if ($order['status'] == OrderClass::ORDER_STATUS_COMPLETE) {
-			$print = ['type' => 'print', 'show' => 1, 'disable' => 1];
-			$send = ['type' => 'send', 'show' => 1, 'disable' => 1];
-			//自取订单不显示发货按钮
-			if ($order['sendType'] == self::SEND_TYPE_NO) {
-				$send['show'] = 0;
-			}
-			return [$print, $send];
-		}
-		return [];
-	}
-	
-	//显示进度 shish 2021.3.1
-	public static function getShowProgress($showProgress, $order)
-	{
-		if ($showProgress == false) {
-			return [];
-		}
-		$create = ['name' => '创建', 'complete' => 1];
-		$unConfirm = ['name' => '待确认', 'complete' => 0];
-		if ($order['status'] > 0) {
-			$unConfirm['complete'] = 1;
-		}
-		$out = ['name' => '出库', 'complete' => 0];
-		if ($order['status'] > 1) {
-			$out['complete'] = 1;
-		}
-		return [$create, $unConfirm, $out];
-	}
-	
-	public static function getShowItem($showItem, $order)
-	{
-		if ($showItem == false) {
-			return ['list' => [], 'itemStat' => []];
-		}
-		$orderSn = $order['orderSn'];
-		$list = OrderItemClass::getOrderItem($orderSn);
-		$totalPrice = 0;
-		$totalBigNum = 0;
-		$totalSmallNum = 0;
-		$kind = 0;
-		$itemStat = [];
-		if (!empty($list)) {
-			foreach ($list as $key => $val) {
-				$list[$key]['property'] = $val['rank'] . '级';
-				$price = $val['price'];
-				$totalPrice = stringUtil::calcAdd($totalPrice, $price);
-				$kind++;
-				$currentBigNum = $val['bigNum'];
-				$currentSmallNum = $val['smallNum'];
-				$totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
-				$totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
-			}
-			$itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
-		}
-		return ['list' => $list, 'itemStat' => $itemStat];
-	}
-	
-	//整合订单员工和供货商等信息 shish 2021.1.19
-	//$isList 是否列表页
-	public static function groupOrder($list, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
-	{
-		if (empty($list)) {
-			return $list;
-		}
-		
-		$customIds = array_unique(array_filter(array_column($list, 'customId')));
-		$customInfo = CustomClass::getCustomByIds($customIds);
-		
-		$adminIds = array_unique(array_filter(array_column($list, 'adminId')));
-		$adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
-		
-		foreach ($list as $key => $val) {
-			$adminId = $val['adminId'] ?? 0;
-			$list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
-			$customId = $val['customId'] ?? 0;
-			$list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
-			$list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
-			$list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
-			$list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
-			//显示列表页的操作按钮
-			$list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
-			//显示进度条
-			$list[$key]['progress'] = self::getShowProgress($showProgress, $val);
-			//显示产品
-			$showItem = self::getShowItem($showItem, $val);
-			$list[$key]['product'] = $showItem['list'];
-			$list[$key]['productStat'] = $showItem['itemStat'];
-			
-			//显示重选花材按钮
-			$showResetItem = 1;
-			//配送中和已完成的不显示重选花材按钮
-			if (in_array($val['sendStatus'], [self::SEND_STATUS_SENDING, self::SEND_STATUS_COMPLETE])) {
-				$showResetItem = 0;
-			}
-			$list[$key]['showResetItem'] = $showResetItem;
-			//获取配送进展
-			$list[$key]['expressProgress'] = OrderExpressClass::getProgress($showExpress, $val);
-		}
-		return $list;
-	}
-	
-	//订单的验证 shish 2021.3.2
-	public static function valid($info, $shopId)
-	{
-		if (empty($info)) {
-			util::fail('没有找到订单');
-		}
-		if (isset($info['shopId']) && $info['shopId'] == $shopId) {
-			return true;
-		}
-		util::fail('没有权限操作的订单');
-	}
-	
-	//获取订单详情 shish 2021.1.21
-	public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
-	{
-		$info = self::getById($id);
-		if (empty($info)) {
-			util::fail('没有找到订单');
-		}
-		$respond = self::groupOrder([$info], $showButton, $showProgress, $showItem, $showExpress, $isList);
-		return current($respond);
-	}
-	
-	//订单到期未付款未确认的订单置成取消状态 shish 2021.1.23
-	public static function setExpire($order)
-	{
-		$now = time();
-		if (isset($order['deadline']) && $now > $order['deadline']) {
-			if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
-				$id = $order['id'];
-				self::updateById($id, ['status' => self::ORDER_STATUS_CANCEL]);
-			}
-		}
-	}
-	
-	//确认送达 shish 2021.3.4
-	public static function reach($order)
-	{
-		if ($order['status'] != OrderClass::ORDER_STATUS_SENDING) {
-			util::fail('订单没有在配送状态');
-		}
-		self::updateById($id, ['status' => self::ORDER_STATUS_COMPLETE, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
-		OrderSendClass::reach($order);
-	}
-	
-	//本店送 shish 2021.1.24
-	public static function selfSend($info)
-	{
-		if ($info['status'] == self::ORDER_STATUS_UN_PAY) {
-			util::fail('订单未付款');
-		}
-		if ($info['status'] != self::ORDER_STATUS_UN_SEND) {
-			util::fail('不是待配送订单');
-		}
-		$id = $info['id'];
-		self::updateById($id, ['status' => self::ORDER_STATUS_SENDING, 'sendType' => self::SEND_TYPE_MYSELF,]);
-		OrderSendClass::selfSend($info);
-	}
-	
-	//自取和免发货流程的处理 shish 2021.1.24
-	public static function withoutSend($order)
-	{
-		$id = $order['id'];
-		if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
-			util::fail('订单已完成');
-		}
-		
-		//订单状态变更
-		self::updateById($id, ['sendType' => self::SEND_TYPE_NO, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
-		self::complete($order, self::TOTAL_FLOW);
-		
-		OrderSendClass::withoutSend($order);
-		
-		//待发货订单-1,完成订单+1
-		$merchantId = $order['merchantId'];
-		$asset = MerchantAssetClass::getByMerchantId($merchantId, true);
-		$asset->finishOrder += 1;
-		$asset->unSendOrder -= 1;
-		$asset->save();
-		
-		return self::TOTAL_FLOW;
-	}
-	
-	//订单完成 shish 2020.3.12
-	public static function complete($order, $currentFlow)
-	{
-		$id = $order['id'];
-		self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]);
-	}
-
-	//支付成功,包括微信支付,支付宝支付,余额支付,欠款支付的后续操作 shish 2021.3.15
-	// $type 1 商家点延期收款 2商家点已付款 3客户微信支付
-	public static function payOk($order, $type)
-	{
-		//不是待付款和待确认订单
-		if ($order['status'] != self::ORDER_STATUS_UN_PAY) {
-			util::fail('已操作过了');
-		}
-
-		//更新订单基础状态和支付状态
-		$unSend = self::ORDER_STATUS_UN_SEND;
-		$upData = ['status' => $unSend];
-		if ($type == 3) {
-			$upData['payStatus'] = 2;
-		}
-		if ($type == 2) {
-			$upData['payStatus'] = 2;
-		}
-		$orderId = $order['id'];
-		$orderSn = $order['orderSn'];
-		self::updateById($orderId, $upData);
-		
-		//增加已下单流程
-		$time = date("Y-m-d H:i:s");
-		$placeData = ['payTime' => $time, 'orderSn' => $orderSn];
-		OrderSendClass::placeOrder($placeData);
-	}
-	
-	//商家操作延期收款的订单 shish 2021.3.15
-	public static function debt($order, $shop)
-	{
-		$customId = $order['customId'] ?? 0;
-		if (empty($customId)) {
-			util::fail('散客订单不能延期收款');
-		}
-		OrderClass::payOk($order, 1);
-		$amount = $order['actPrice'] ?? 0.00;
-		$customInfo = CustomClass::getCustom($customId);
-		$debtAmount = bcadd($customInfo['debtAmount'], $amount, 2);
-		CustomClass::updateById($customId, ['debtAmount' => $debtAmount, 'isDebt' => 1]);
-	}
-	
+
+    public static $baseFile = '\bizGhs\order\models\Order';
+
+    //已退款
+    const ORDER_STATUS_REFUND = 6;
+    //已取消
+    const ORDER_STATUS_CANCEL = 5;
+    //已完成
+    const ORDER_STATUS_COMPLETE = 4;
+    //配送中
+    const ORDER_STATUS_SENDING = 3;
+    //待配送
+    const ORDER_STATUS_UN_SEND = 2;
+    //待付款,待确认
+    const ORDER_STATUS_UN_PAY = 1;
+
+    //未确认
+    const SEND_TYPE_UNKNOWN = 1;
+    //自取
+    const SEND_TYPE_NO = 2;
+    //自己送
+    const SEND_TYPE_MYSELF = 3;
+    //快递送
+    const SEND_TYPE_THIRD = 4;
+
+    //待付款,待确认
+    const PAY_STATUS_UN_PAY = 1;
+    //已付款
+    const PAY_STATUS_HAS_PAY = 2;
+
+    //待配送
+    const SEND_STATUS_UN_SEND = 1;
+    //配送中
+    const SEND_STATUS_SENDING = 2;
+    //配送完成
+    const SEND_STATUS_COMPLETE = 3;
+
+    //订单总流程数
+    const TOTAL_FLOW = 3;
+
+    //添加订单 shish 2019.12.5
+    public static function addOrder($data)
+    {
+        $merchantId = $data['merchantId'] ?? 0;
+        $month = date("Ym");
+        $orderSn = orderSn::getGhsOrderSn();
+        $data['orderSn'] = $orderSn;
+        $data['payStatus'] = self::PAY_STATUS_UN_PAY;
+
+        //花材列表
+        $product = $data['product'];
+        OrderItemClass::replace(['orderSn' => $orderSn], $product, true);
+
+        //将花店每月的总订单数作为编号
+        $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
+        $data['sendNum'] = $riseNum;
+        $data['num'] = 1;
+        $data['smallNum'] = 1;
+        $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
+        //订单30分钟后过期
+        $data['deadline'] = date("Y-m-d H:i:s", (time() + 1800));
+        $data['sendCost'] = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
+        $return = self::add($data);
+        $orderId = $return['id'];
+
+        //全部订单+1,待付款订单+1
+        $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $merchantAsset->unPayOrder += 1;
+        $merchantAsset->totalOrder += 1;
+        $merchantAsset->save();
+
+        //增加下单流程
+        $payTime = date("Y-m-d H:i:s");
+        $sendData = ['orderId' => $orderId, 'orderSn' => $orderSn, 'payTime' => $payTime];
+        OrderSendClass::placeOrder($sendData);
+
+        //扣库存 2021.2.23 linqh
+        foreach ($product as $key => $val) {
+            ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum']);
+        }
+        return $return;
+    }
+
+    //根据订单编号查询 shish 2021.19
+    public static function getByOrderSn($orderSn)
+    {
+        return self::getByCondition(['orderSn' => $orderSn]);
+    }
+
+    //订单列表 shish 2021.1.19
+    public static function getOrderList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        $data['list'] = self::groupOrder($data['list'], true, false, false, false, true);
+        $data['allNum'] = 0;
+        $data['unPayNum'] = 0;
+        $data['unSendNum'] = 0;
+        $data['sendingNum'] = 0;
+        $data['finishNum'] = 0;
+        return $data;
+    }
+
+    //显示操作按钮
+    public static function getShowButton($showButton, $isList, $order)
+    {
+        if ($showButton == false) {
+            return [];
+        }
+        //列表页显示的按钮
+        if ($isList) {
+            $item = ['type' => 'item', 'show' => 1, 'disable' => 1];
+            $send = ['type' => 'send', 'show' => 1, 'disable' => 0];
+            $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
+            if (in_array($order['status'], [self::ORDER_STATUS_UN_PAY, self::ORDER_STATUS_UN_SEND])) {
+                //待付款和待配送订单,改花材按钮才能点击
+                $item['disable'] = 0;
+            }
+            if ($order['sendType'] == self::SEND_TYPE_NO) {
+                //自取订单,发货按钮不可点
+                $send['disable'] = 1;
+            }
+            if ($order['sendType'] == self::SEND_TYPE_UNKNOWN) {
+                //只有未确认配送方式的订单才可点击自取
+                $selfGet['disable'] = 0;
+            }
+            return [$item, $send, $selfGet];
+        }
+
+        //待确认订单显示延期付和已付款
+        if ($order['status'] == OrderClass::ORDER_STATUS_UN_PAY) {
+            $debtPay = ['type' => 'debtPay', 'show' => 1, 'disable' => 0];
+            $hasPay = ['type' => 'hasPay', 'show' => 1, 'disable' => 0];
+            return [$debtPay, $hasPay];
+        }
+
+        //待配送订单显示打印、发货和自取
+        if ($order['status'] == OrderClass::ORDER_STATUS_UN_SEND) {
+            //没有花材的订单按钮全部置灰色不可点
+            $print = ['type' => 'print', 'show' => 0, 'disable' => 1];
+            $item = ['type' => 'item', 'show' => 1, 'disable' => 1];
+            $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
+            $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
+            if ($order['hasItem'] == 2) {
+                return [$print, $item, $selfGet, $send];
+            }
+            $print['disable'] = 0;
+            $selfGet['disable'] = 0;
+            $send['disable'] = 0;
+            $item['disable'] = 0;
+            return [$print, $item, $selfGet, $send];
+        }
+        //配送中显示按钮
+        if ($order['status'] == OrderClass::ORDER_STATUS_SENDING) {
+            $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
+            $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
+            return [$print, $send];
+        }
+        if ($order['status'] == OrderClass::ORDER_STATUS_COMPLETE) {
+            $print = ['type' => 'print', 'show' => 1, 'disable' => 1];
+            $send = ['type' => 'send', 'show' => 1, 'disable' => 1];
+            //自取订单不显示发货按钮
+            if ($order['sendType'] == self::SEND_TYPE_NO) {
+                $send['show'] = 0;
+            }
+            return [$print, $send];
+        }
+        return [];
+    }
+
+    //显示进度 shish 2021.3.1
+    public static function getShowProgress($showProgress, $order)
+    {
+        if ($showProgress == false) {
+            return [];
+        }
+        $create = ['name' => '创建', 'complete' => 1];
+        $unConfirm = ['name' => '待确认', 'complete' => 0];
+        if ($order['status'] > 0) {
+            $unConfirm['complete'] = 1;
+        }
+        $out = ['name' => '出库', 'complete' => 0];
+        if ($order['status'] > 1) {
+            $out['complete'] = 1;
+        }
+        return [$create, $unConfirm, $out];
+    }
+
+    public static function getShowItem($showItem, $order)
+    {
+        if ($showItem == false) {
+            return ['list' => [], 'itemStat' => []];
+        }
+        $orderSn = $order['orderSn'];
+        $list = OrderItemClass::getOrderItem($orderSn);
+        $totalPrice = 0;
+        $totalBigNum = 0;
+        $totalSmallNum = 0;
+        $kind = 0;
+        $itemStat = [];
+        if (!empty($list)) {
+            foreach ($list as $key => $val) {
+                $list[$key]['property'] = $val['rank'] . '级';
+                $price = $val['price'];
+                $totalPrice = stringUtil::calcAdd($totalPrice, $price);
+                $kind++;
+                $currentBigNum = $val['bigNum'];
+                $currentSmallNum = $val['smallNum'];
+                $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
+                $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
+            }
+            $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
+        }
+        return ['list' => $list, 'itemStat' => $itemStat];
+    }
+
+    //整合订单员工和供货商等信息 shish 2021.1.19
+    //$isList 是否列表页
+    public static function groupOrder($list, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
+    {
+        if (empty($list)) {
+            return $list;
+        }
+
+        $customIds = array_unique(array_filter(array_column($list, 'customId')));
+        $customInfo = CustomClass::getCustomByIds($customIds);
+
+        $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
+        $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
+
+        foreach ($list as $key => $val) {
+            $adminId = $val['adminId'] ?? 0;
+            $list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
+            $customId = $val['customId'] ?? 0;
+            $list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
+            $list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
+            $list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
+            $list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
+            //显示列表页的操作按钮
+            $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
+            //显示进度条
+            $list[$key]['progress'] = self::getShowProgress($showProgress, $val);
+            //显示产品
+            $showItem = self::getShowItem($showItem, $val);
+            $list[$key]['product'] = $showItem['list'];
+            $list[$key]['productStat'] = $showItem['itemStat'];
+
+            //显示重选花材按钮
+            $showResetItem = 1;
+            //配送中和已完成的不显示重选花材按钮
+            if (in_array($val['sendStatus'], [self::SEND_STATUS_SENDING, self::SEND_STATUS_COMPLETE])) {
+                $showResetItem = 0;
+            }
+            $list[$key]['showResetItem'] = $showResetItem;
+            //获取配送进展
+            $list[$key]['expressProgress'] = OrderExpressClass::getProgress($showExpress, $val);
+        }
+        return $list;
+    }
+
+    //订单的验证 shish 2021.3.2
+    public static function valid($info, $shopId)
+    {
+        if (empty($info)) {
+            util::fail('没有找到订单');
+        }
+        if (isset($info['shopId']) && $info['shopId'] == $shopId) {
+            return true;
+        }
+        util::fail('没有权限操作的订单');
+    }
+
+    //获取订单详情 shish 2021.1.21
+    public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showItem = false, $showExpress = false, $isList = false)
+    {
+        $info = self::getById($id);
+        if (empty($info)) {
+            util::fail('没有找到订单');
+        }
+        $respond = self::groupOrder([$info], $showButton, $showProgress, $showItem, $showExpress, $isList);
+        return current($respond);
+    }
+
+    //订单到期未付款未确认的订单置成取消状态 shish 2021.1.23
+    public static function setExpire($order)
+    {
+        $now = time();
+        if (isset($order['deadline']) && $now > $order['deadline']) {
+            if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
+                $id = $order['id'];
+                self::updateById($id, ['status' => self::ORDER_STATUS_CANCEL]);
+            }
+        }
+    }
+
+    //确认送达 shish 2021.3.4
+    public static function reach($order)
+    {
+        if ($order['status'] != OrderClass::ORDER_STATUS_SENDING) {
+            util::fail('订单没有在配送状态');
+        }
+        self::updateById($id, ['status' => self::ORDER_STATUS_COMPLETE, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
+        OrderSendClass::reach($order);
+    }
+
+    //本店送 shish 2021.1.24
+    public static function selfSend($info)
+    {
+        if ($info['status'] == self::ORDER_STATUS_UN_PAY) {
+            util::fail('订单未付款');
+        }
+        if ($info['status'] != self::ORDER_STATUS_UN_SEND) {
+            util::fail('不是待配送订单');
+        }
+        $id = $info['id'];
+        self::updateById($id, ['status' => self::ORDER_STATUS_SENDING, 'sendType' => self::SEND_TYPE_MYSELF,]);
+        OrderSendClass::selfSend($info);
+    }
+
+    //自取和免发货流程的处理 shish 2021.1.24
+    public static function withoutSend($order)
+    {
+        $id = $order['id'];
+        if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
+            util::fail('订单已完成');
+        }
+
+        //订单状态变更
+        self::updateById($id, ['sendType' => self::SEND_TYPE_NO, 'totalFlow' => OrderClass::TOTAL_FLOW, 'currentFlow' => OrderClass::TOTAL_FLOW]);
+        self::complete($order, self::TOTAL_FLOW);
+
+        OrderSendClass::withoutSend($order);
+
+        //待发货订单-1,完成订单+1
+        $merchantId = $order['merchantId'];
+        $asset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $asset->finishOrder += 1;
+        $asset->unSendOrder -= 1;
+        $asset->save();
+
+        return self::TOTAL_FLOW;
+    }
+
+    //订单完成 shish 2020.3.12
+    public static function complete($order, $currentFlow)
+    {
+        $id = $order['id'];
+        self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => $currentFlow]);
+    }
+
+    //支付成功,包括微信支付,支付宝支付,余额支付,欠款支付的后续操作 shish 2021.3.15
+    // $type 1 商家点延期收款 2商家点已付款 3客户微信支付
+    public static function payOk($order, $type)
+    {
+        //不是待付款和待确认订单
+        if ($order['status'] != self::ORDER_STATUS_UN_PAY) {
+            util::fail('已操作过了');
+        }
+
+        //更新订单基础状态和支付状态
+        $unSend = self::ORDER_STATUS_UN_SEND;
+        $upData = ['status' => $unSend];
+        if ($type == 3) {
+            $upData['payStatus'] = 2;
+        }
+        if ($type == 2) {
+            $upData['payStatus'] = 2;
+        }
+        $orderId = $order['id'];
+        $orderSn = $order['orderSn'];
+        self::updateById($orderId, $upData);
+
+        StatYjClass::addYj($order);
+
+        //增加已下单流程
+        $time = date("Y-m-d H:i:s");
+        $placeData = ['payTime' => $time, 'orderSn' => $orderSn];
+        OrderSendClass::placeOrder($placeData);
+    }
+
+    //商家操作延期收款的订单 shish 2021.3.15
+    public static function debt($order, $shop)
+    {
+        $customId = $order['customId'] ?? 0;
+        if (empty($customId)) {
+            util::fail('散客订单不能延期收款');
+        }
+        OrderClass::payOk($order, 1);
+        $amount = $order['actPrice'] ?? 0.00;
+        $customInfo = CustomClass::getCustom($customId);
+        $debtAmount = bcadd($customInfo['debtAmount'], $amount, 2);
+        CustomClass::updateById($customId, ['debtAmount' => $debtAmount, 'isDebt' => 1]);
+    }
+
 }

+ 62 - 39
biz-ghs/stat/classes/StatYjClass.php

@@ -3,49 +3,72 @@
 namespace bizGhs\stat\classes;
 
 use bizGhs\shop\classes\ShopAdminClass;
+use bizGhs\shop\models\ShopAdmin;
 use common\components\arrayUtil;
 use Yii;
 use bizGhs\base\classes\BaseClass;
 
 class StatYjClass extends BaseClass
 {
-	
-	public static $baseFile = '\bizGhs\stat\models\StatYj';
-	
-	//业绩列表 shish 2021.3.15
-	public static function getYjList($where)
-	{
-		$data = self::getList('*', $where, 'addTime DESC');
-		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-		if (empty($list)) {
-			return $data;
-		}
-		foreach ($data['list'] as $key => $val) {
-			$shopAdminId = $val['shopAdminId'];
-			if (isset($arr[$shopAdminId]) == false) {
-				$arr[$shopAdminId] = ['amount' => 0, 'num' => 0];
-			}
-			$arr[$shopAdminId]['amount'] = bcadd($val['amount'], $arr[$shopAdminId]['amount'], 2);
-			$arr[$shopAdminId]['num'] = bcadd($val['num'], $arr[$shopAdminId]['num']);
-		}
-		$ids = array_keys($arr);
-		$admin = ShopAdminClass::getByIds($ids);
-		$show = [];
-		foreach ($admin as $key => $val) {
-			$adminId = $val['id'];
-			$adminName = $val['adminName'] ?? '';
-			$amount = $arr[$adminId]['amount'] ?? 0.00;
-			$num = $arr[$adminId]['num'] ?? 0;
-			$show[] = [
-				'adminName' => $adminName,
-				'amount' => $amount,
-				'num' => $num,
-				'id' => $val['id'],
-			];
-		}
-		//排序
-		$show = arrayUtil::arraySort($show, 'amount');
-		return $show;
-	}
-	
+
+    public static $baseFile = '\bizGhs\stat\models\StatYj';
+
+    //业绩列表 shish 2021.3.15
+    public static function getYjList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        foreach ($data['list'] as $key => $val) {
+            $shopAdminId = $val['shopAdminId'];
+            if (isset($arr[$shopAdminId]) == false) {
+                $arr[$shopAdminId] = ['amount' => 0, 'num' => 0];
+            }
+            $arr[$shopAdminId]['amount'] = bcadd($val['amount'], $arr[$shopAdminId]['amount'], 2);
+            $arr[$shopAdminId]['num'] = bcadd($val['num'], $arr[$shopAdminId]['num']);
+        }
+        $ids = array_keys($arr);
+        $admin = ShopAdminClass::getByIds($ids);
+        $show = [];
+        foreach ($admin as $key => $val) {
+            $adminId = $val['id'];
+            $adminName = $val['adminName'] ?? '';
+            $amount = $arr[$adminId]['amount'] ?? 0.00;
+            $num = $arr[$adminId]['num'] ?? 0;
+            $show[] = [
+                'adminName' => $adminName,
+                'amount' => $amount,
+                'num' => $num,
+                'id' => $val['id'],
+            ];
+        }
+        //排序
+        $show = arrayUtil::arraySort($show, 'amount');
+        return $show;
+    }
+
+    public static function addYj($order, $date = null)
+    {
+        $shopAdminId = $order['shopAdminId'] ?? 0;
+        if (empty($shopAdminId)) {
+            return false;
+        }
+        $admin = ShopAdminClass::getById($shopAdminId);
+        $sjId = $admin['merchantId'] ?? 0;
+        $shopId = $admin['shopId'] ?? 0;
+        $date = isset($date) ? $date : date("Ymd");
+        $stat = self::getByCondition(['shopAdminId' => $shopAdminId, 'time' => $date], true);
+        if (empty($stat)) {
+            $stat = self::add(['sjId' => $sjId, 'shopId' => $shopId, 'shopAdminId' => $shopAdminId, 'time' => $date], true);
+        }
+        $stat->num += 1;
+        $stat->totalNum += 1;
+        $stat->amount = bcadd($order['actPrice'], $stat->amount, 2);
+        $stat->totalAmount = bcadd($order['actPrice'], $stat->totalAmount, 2);
+        $stat->save();
+        StatYjMonthClass::addYj($order);
+    }
+
 }

+ 38 - 0
biz-ghs/stat/classes/StatYjMonthClass.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace bizGhs\stat\classes;
+
+use bizGhs\shop\classes\ShopAdminClass;
+use common\components\arrayUtil;
+use Yii;
+use bizGhs\base\classes\BaseClass;
+
+class StatYjMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\stat\models\StatYjMonth';
+
+    //增加业绩 shish 2021.3.15
+    public static function addYj($order, $month = null)
+    {
+        $shopAdminId = $order['shopAdminId'] ?? 0;
+        if (empty($shopAdminId)) {
+            return false;
+        }
+        $admin = ShopAdminClass::getById($shopAdminId);
+        $sjId = $admin['merchantId'] ?? 0;
+        $shopId = $admin['shopId'] ?? 0;
+        $month = isset($month) ? $month : date("Ym");
+        $stat = self::getByCondition(['sjId' => $sjId, 'time' => $month], true);
+        if (empty($stat)) {
+            $stat = self::add(['sjId' => $sjId, 'time' => $month, 'shopId' => $shopId, 'shopAdminId' => $shopAdminId], true);
+        }
+        $stat->num += 1;
+        $stat->totalNum += 1;
+        $stat->amount = bcadd($order['actPrice'], $stat->amount, 2);
+        $stat->totalAmount = bcadd($order['actPrice'], $stat->totalAmount, 2);
+        $stat->save();
+        $stat->save();
+    }
+
+}

+ 15 - 0
biz-ghs/stat/models/StatYjMonth.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizGhs\stat\models;
+
+use bizGhs\base\models\Base;
+
+class StatYjMonth extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsStatYjMonth';
+    }
+
+}