Browse Source

分类与用途

shish 6 years ago
parent
commit
49322e2aff

+ 13 - 1
app/business/controllers/OrderController.php

@@ -36,5 +36,17 @@ class OrderController extends BaseController
 		$detail = OrderService::getDetail();
 		util::success($detail);
 	}
-
+	
+	//订单归类 shish 2019.12.17
+	public function actionClassify()
+	{
+		$post = Yii::$app->request->post();
+		$id = isset($post['id']) ? $post['id'] : 0;
+		$order = OrderService::getById($id);
+		OrderService::valid($order, $this->merchantId);
+		unset($post['id']);
+		OrderService::classify($id, $post);
+		util::ok();
+	}
+	
 }

+ 2 - 2
app/business/controllers/OrderSendController.php

@@ -78,12 +78,12 @@ class OrderSendController extends BaseController
 	{
 	
 	}
-	
+
 	//快递服务提供方
 	public function actionExpressProvide()
 	{
 		$data = ['id' => 1, 'name' => '达达'];
 		util::success($data);
 	}
-	
+
 }

+ 30 - 4
biz/order/services/OrderService.php

@@ -103,11 +103,37 @@ class OrderService extends BaseService
 	{
 		return OrderClass::comment($data);
 	}
-
-	//订单详情 shish 2019.12.16
-	public static function getDetail()
-	{
 	
+	//订单归类
+	public static function classify($id, $data)
+	{
+		$connection = Yii::$app->db;//事务处理
+		$transaction = $connection->beginTransaction();
+		try {
+			$id = $data['id'];
+			$order = OrderClass::getById($id, true);
+			if ($order->payStatus != 1) {
+				util::fail('订单还未付款');
+			}
+			if (!empty($order->categoryId) && !empty($order->usageId)) {
+				util::fail('已经归类过了');
+			}
+			$categoryId = $data['categoryId'];
+			$usageId = $data['usageId'];
+			$order->categoryId = $categoryId;
+			$order->usageId = $usageId;
+			$order->save();
+			
+			//设置流水的分类和用途并分配资金
+			$setData = ['merchantId' => $order->merchantId, 'capitalId' => $order->capitalId, 'time' => $order->payTime,
+				'usageId' => $order->usageId, 'categoryId' => $order->categoryId, 'amount' => $order->actPrice, 'payWay' => $order->payWay];
+			MerchantCapitalService::setCategoryUsage($setData);
+
+			$transaction->commit();
+		} catch (Exception $e) {
+			$transaction->rollBack();
+			util::fail('没有归类成功');
+		}
 	}
 	
 }

+ 12 - 0
biz/stat/classes/StatIncomeUsageClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\stat\classes;
+use Yii;
+use biz\base\classes\BaseClass;
+
+class StatIncomeUsageClass extends BaseClass
+{
+	
+	public static $baseFile = '\biz\stat\models\StatIncomeUsage';
+	
+}

+ 13 - 0
biz/stat/classes/StatIncomeUsageMonthClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\stat\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class StatIncomeUsageMonthClass extends BaseClass
+{
+	
+	public static $baseFile = '\biz\stat\models\StatIncomeUsageMonth';
+	
+}

+ 13 - 0
biz/stat/models/StatIncomeUsage.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\stat\models;
+use biz\base\models\Base;
+
+class StatIncomeUsage extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhStatIncomeUsage';
+	}
+
+}

+ 13 - 0
biz/stat/models/StatIncomeUsageMonth.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\stat\models;
+use biz\base\models\Base;
+
+class StatIncomeUsageMonth extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhStatIncomeUsageMonth';
+	}
+
+}

+ 0 - 3
biz/stat/services/StatIncomeCategoryMonthService.php

@@ -4,7 +4,6 @@ namespace biz\stat\services;
 
 use biz\base\services\BaseService;
 use common\components\business;
-use common\components\validate;
 use Yii;
 
 class StatIncomeCategoryMonthService extends BaseService
@@ -15,8 +14,6 @@ class StatIncomeCategoryMonthService extends BaseService
 	//添加更新记录 shish 2019.9.16
 	public static function replaceData($data)
 	{
-		$valid = ['categoryId', 'amount', 'merchantId', 'payWay'];
-		validate::easyCheck($valid, $data);
 		$merchantId = $data['merchantId'];
 		$categoryId = $data['categoryId'];
 		$amount = $data['amount'];

+ 0 - 3
biz/stat/services/StatIncomeCategoryService.php

@@ -6,7 +6,6 @@ use biz\base\services\BaseService;
 use biz\goods\services\CategoryRelateService;
 use common\components\business;
 use common\components\stringUtil;
-use common\components\validate;
 use common\components\util;
 use Yii;
 
@@ -18,8 +17,6 @@ class StatIncomeCategoryService extends BaseService
 	//添加更新记录 shish 2010.8.20
 	public static function replaceData($data)
 	{
-		$valid = ['categoryId', 'amount', 'merchantId', 'payWay'];
-		validate::easyCheck($valid, $data);
 		$time = date("Ymd");
 		if (isset($data['time'])) {
 			//如果传time参数必须是时间戳

+ 33 - 0
biz/stat/services/StatIncomeUsageMonthService.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace biz\stat\services;
+
+use biz\base\services\BaseService;
+use common\components\business;
+use Yii;
+
+class StatIncomeUsageMonthService extends BaseService
+{
+	
+	public static $baseFile = '\biz\stat\classes\StatIncomeUsageMonthClass';
+	
+	//添加更新记录 shish 2019.9.16
+	public static function replaceData($data)
+	{
+		$merchantId = $data['merchantId'];
+		$usageId = $data['usageId'];
+		$amount = $data['amount'];
+		$data['year'] = isset($data['year']) ? $data['year'] : date("Y");
+		$data['month'] = isset($data['month']) ? $data['month'] : date("n");
+		$income = self::getByCondition(['merchantId' => $merchantId, 'year' => $data['year'], 'month' => $data['month'], 'usageId' => $usageId], true);
+		if (empty($income)) {
+			$income = self::add($data, true);
+		} else {
+			$income->amount += $amount;
+		}
+		$income = business::savePayWayAmount($income, $amount, $data['payWay']);
+		$income->save();
+		return true;
+	}
+	
+}

+ 73 - 0
biz/stat/services/StatIncomeUsageService.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace biz\stat\services;
+
+use biz\base\services\BaseService;
+use biz\goods\services\UsageRelationService;
+use common\components\business;
+use common\components\stringUtil;
+use common\components\validate;
+use common\components\util;
+use Yii;
+
+class StatIncomeUsageService extends BaseService
+{
+	
+	public static $baseFile = '\biz\stat\classes\StatIncomeUsageClass';
+	
+	//添加更新记录 shish 2010.8.20
+	public static function replaceData($data)
+	{
+		$valid = ['usageId', 'amount', 'merchantId', 'payWay'];
+		validate::easyCheck($valid, $data);
+		$time = date("Ymd");
+		if (isset($data['time'])) {
+			//如果传time参数必须是时间戳
+			if (strtotime(date('Y-m-d H:i:s', $data['time'])) != $data['time']) {
+				util::fail('time不是时间戳');
+			}
+			$time = date("Ymd", $data['time']);
+			$data['time'] = $time;
+		}
+		$merchantId = $data['merchantId'];
+		$usageId = $data['usageId'];
+		$amount = $data['amount'];
+		$payWay = $data['payWay'];
+		$income = self::getByCondition(['merchantId' => $merchantId, 'time' => $time, 'usageId' => $usageId], true);
+		if (empty($income)) {
+			$income = self::add($data, true);
+		} else {
+			$income->amount += $data['amount'];
+		}
+		business::savePayWayAmount($income, $amount, $payWay);
+		
+		/**每个月增加**/
+		StatIncomeUsageMonthService::replaceData($data);
+		
+		$income->save();
+	}
+
+	public static function getLatestIncome($start, $end)
+	{
+		$merchantId = Yii::$app->params['merchantId'];
+		$list = self::getAllList('usageId,amount', ['merchantId' => $merchantId, 'time' => ['between', [$start, $end]]], 'time asc');
+		$totalAmount = 0;
+		$usageList = UsageRelationService::getMyUsage();
+		$data = [];
+		foreach ($usageList as $usageId => $category) {
+			$data[$usageId]['name'] = $category['showName'];
+			$data[$usageId]['value'] = 0;
+		}
+		if (!empty($list)) {
+			foreach ($list as $val) {
+				$usageId = $val['usageId'];
+				$amount = $val['amount'];
+				$data[$usageId]['value'] = stringUtil::calcAdd($data[$usageId]['value'], $amount);
+				$totalAmount = stringUtil::calcAdd($totalAmount, $amount);
+			}
+		}
+		$usageName = array_column($usageList, 'showName');
+		return ['data' => array_values($data), 'usageName' => $usageName, 'totalAmount' => $totalAmount];
+	}
+
+}

+ 33 - 1
sql.txt

@@ -1,8 +1,41 @@
+2019.12.17 shish
+drop table if exists `xhStatIncomeUsage`;
+CREATE TABLE if not exists `xhStatIncomeUsage` (
+  `id` int(11) NOT NULL auto_increment primary key,
+  `merchantId` int(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+  `shopId` int not null default 0 comment '门店id,0表示商家所有门店',
+  `time` int(11) NOT NULL DEFAULT '0' COMMENT '时间',
+  `usageId` tinyint(4) NOT NULL DEFAULT '0' COMMENT '用途id;UsageRelation id',
+  `amount` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '收入金额',
+  `weixin` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '微信收入',
+  `alipay` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '支付宝收入',
+  `balancePay` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '余额付款收入',
+  `cash` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '现金收入',
+  `totalAmount` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '总收入金额',
+  `addTime` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间'
+) COMMENT='按用途统计每天收入';
+drop table if exists `xhStatIncomeUsageMonth`;
+CREATE TABLE if not exists `xhStatIncomeUsageMonth` (
+  `id` int(11) NOT NULL auto_increment primary key,
+  `year` smallint(6) NOT NULL DEFAULT '0' COMMENT '年',
+  `month` tinyint(4) NOT NULL DEFAULT '1' COMMENT '月份',
+  `usageId` tinyint(4) NOT NULL DEFAULT '0' COMMENT '用途id',
+  `amount` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '收入金额',
+  `weixin` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '微信收入',
+  `alipay` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '支付宝收入',
+  `balancePay` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '余额付款收入',
+  `cash` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '现金收入',
+  `merchantId` int(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+`shopId` int not null default 0 comment '门店id,0表示商家所有门店',
+  `addTime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '添加时间'
+) COMMENT='按用途统计每月收入';
+
 2019.12.15 16:30 shish 数据要重新更新过去!!!!!
 ALTER TABLE xhOrder ADD `reachDate` DATE DEFAULT NULL COMMENT '客户要求送到的日期' AFTER `sendDistance`;
 ALTER TABLE xhOrder DROP COLUMN `reachTime`;
 ALTER TABLE xhOrder MODIFY `reachPeriod` TINYINT NOT NULL DEFAULT 0 COMMENT '客户要求送到的时段:0上午1下午2晚上';
 ALTER TABLE xhOrder ADD sendTip DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '运费里增加的小费' AFTER `sendCost`;
+ALTER TABLE xhOrder MODIFY currentFlow TINYINT NOT NULL DEFAULT 0 COMMENT '完成流程数;当前流程数';
 
 2019.12.15 11:57 刮刮卡表名变更
 RENAME TABLE xhGuaGua TO xhGgk;
@@ -450,7 +483,6 @@ auth VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '权限',
 `addTime` INT(11) NOT NULL DEFAULT '0' COMMENT '添加时间'
 )COMMENT='员工角色权限'
 
-
 shish 2019.11.23
 !!jwt的过期时间要设置得短点