소스 검색

订单花材列表优化

shish 5 년 전
부모
커밋
1d814d1a81
3개의 변경된 파일314개의 추가작업 그리고 283개의 파일을 삭제
  1. 270 268
      biz-ghs/order/classes/OrderClass.php
  2. 36 14
      biz-ghs/order/classes/OrderItemClass.php
  3. 8 1
      sql.sql

+ 270 - 268
biz-ghs/order/classes/OrderClass.php

@@ -15,272 +15,274 @@ use bizGhs\base\classes\BaseClass;
 
 class OrderClass extends BaseClass
 {
-
-    public static $baseFile = '\bizGhs\order\models\Order';
-
-
-    //已完成
-    const ORDER_STATUS_COMPLETE = 6;
-    //已取消
-    const ORDER_STATUS_CANCEL = 5;
-    //待通知
-    const ORDER_STATUS_UN_NOTICE = 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, $product);
-
-        //将花店每月的总订单数作为编号
-        $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['num'], $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);
-        $data['allNum'] = 0;
-        $data['unPayNum'] = 0;
-        $data['unSendNum'] = 0;
-        $data['sendingNum'] = 0;
-        $data['finishNum'] = 0;
-        return $data;
-    }
-
-    //显示操作按钮
-    public static function getShowButton($showButton, $order)
-    {
-        if ($showButton == false) {
-            return [];
-        }
-        $item = ['type' => 'item', 'show' => 1, 'disable' => 0];
-        if ($order['sendStatus'] > 0) {
-            //只有待发货订单,花材按钮才能点击
-            $item['disable'] = 1;
-        }
-        $send = ['type' => 'send', 'show' => 1, 'disable' => 0];
-        if ($order['sendType'] == 1) {
-            //自取订单,发货按钮不可点
-            $send['disable'] = 1;
-        }
-        $selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
-        if ($order['sendType'] == 0) {
-            //只有未确认配送方式的订单才可点击自取
-            $selfGet['disable'] = 0;
-        }
-        return [$item, $send, $selfGet];
-    }
-
-    //显示进度 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 getShowProduct($showProduct, $order)
-    {
-        if ($showProduct == false) {
-            return [];
-        }
-        return [
-            [
-                'cover' => 'https://img.huahb.com/uploads/12358/202101/13/0e713d46064ca89b1fb11095b710f244_small.jpeg',
-                'name' => '昆明B级红玫瑰卡罗拉', 'property' => 'B级', 'price' => '8.45', 'bigNum' => 2, 'smallNum' => 10, 'id' => 16,
-            ],
-        ];
-    }
-
-    //整合订单员工和供货商等信息 shish 2021.1.19
-    public static function groupOrder($list, $showButton = false, $showProgress = false, $showProduct = 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, $val);
-            //显示进度条
-            $list[$key]['progress'] = self::getShowProgress($showProgress, $val);
-            //显示产品
-            $list[$key]['product'] = self::getShowProduct($showProduct, $val);
-        }
-        return $list;
-    }
-
-    public static function valid($info, $shopId)
-    {
-        if (isset($info['shopId']) && $info['shopId'] == $shopId) {
-            return true;
-        }
-        util::fail('没有权限操作的订单');
-    }
-
-    //获取订单详情 shish 2021.1.21
-    public static function getOrderInfo($id, $showButton = false, $showProgress = false, $showProduct = false)
-    {
-        $info = self::getById($id);
-        $respond = self::groupOrder([$info], $showButton, $showProgress, $showProduct);
-        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.1.24
-    public static function selfSend($info)
-    {
-        if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_PAY) {
-            util::fail('订单不是待配送状态!');
-        }
-        if (isset($info['status']) == false || $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,
-        ]);
-    }
-
-    //自取和免发货流程的处理 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]);
-    }
-
+	
+	public static $baseFile = '\bizGhs\order\models\Order';
+	
+	
+	//已完成
+	const ORDER_STATUS_COMPLETE = 6;
+	//已取消
+	const ORDER_STATUS_CANCEL = 5;
+	//待通知
+	const ORDER_STATUS_UN_NOTICE = 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, $product);
+		
+		//将花店每月的总订单数作为编号
+		$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['num'], $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);
+		$data['allNum'] = 0;
+		$data['unPayNum'] = 0;
+		$data['unSendNum'] = 0;
+		$data['sendingNum'] = 0;
+		$data['finishNum'] = 0;
+		return $data;
+	}
+	
+	//显示操作按钮
+	public static function getShowButton($showButton, $order)
+	{
+		if ($showButton == false) {
+			return [];
+		}
+		$item = ['type' => 'item', 'show' => 1, 'disable' => 0];
+		if ($order['sendStatus'] > 0) {
+			//只有待发货订单,花材按钮才能点击
+			$item['disable'] = 1;
+		}
+		$send = ['type' => 'send', 'show' => 1, 'disable' => 0];
+		if ($order['sendType'] == 1) {
+			//自取订单,发货按钮不可点
+			$send['disable'] = 1;
+		}
+		$selfGet = ['type' => 'selfGet', 'show' => 1, 'disable' => 1];
+		if ($order['sendType'] == 0) {
+			//只有未确认配送方式的订单才可点击自取
+			$selfGet['disable'] = 0;
+		}
+		return [$item, $send, $selfGet];
+	}
+	
+	//显示进度 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 [];
+		}
+		$orderSn = $order['orderSn'];
+		$list = OrderItemClass::getOrderItem($orderSn);
+		if (!empty($list)) {
+			foreach ($list as $key => $val) {
+				$list[$key]['property'] = $val['rank'] . '级';
+			}
+		}
+		return $list;
+	}
+
+	//整合订单员工和供货商等信息 shish 2021.1.19
+	public static function groupOrder($list, $showButton = false, $showProgress = false, $showItem = 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, $val);
+			//显示进度条
+			$list[$key]['progress'] = self::getShowProgress($showProgress, $val);
+			//显示产品
+			$list[$key]['product'] = self::getShowItem($showItem, $val);
+		}
+		return $list;
+	}
+	
+	public static function valid($info, $shopId)
+	{
+		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)
+	{
+		$info = self::getById($id);
+		$respond = self::groupOrder([$info], $showButton, $showProgress, $showItem);
+		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.1.24
+	public static function selfSend($info)
+	{
+		if (isset($info['status']) == false || $info['status'] != self::ORDER_STATUS_UN_PAY) {
+			util::fail('订单不是待配送状态!');
+		}
+		if (isset($info['status']) == false || $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,
+		]);
+	}
+	
+	//自取和免发货流程的处理 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]);
+	}
+	
 }

+ 36 - 14
biz-ghs/order/classes/OrderItemClass.php

@@ -9,20 +9,42 @@ use bizGhs\base\classes\BaseClass;
 class OrderItemClass extends BaseClass
 {
 
-    public static $baseFile = '\bizGhs\order\models\OrderItem';
+	public static $baseFile = '\bizGhs\order\models\OrderItem';
 
-    //添加和修改花材
-    public static function replace($orderSn, $product)
-    {
-    	//快速付款没有商品
-    	if(empty($product)){
-    		return false;
-	    }
-        self::deleteByCondition(['orderSn' => $orderSn]);
-        foreach ($product as $key => $val) {
-            $product[$key]['orderSn'] = $orderSn;
-        }
-        self::batchAdd($product);
-    }
+	//获取订单的花材 shish 2021.3.2
+	public static function getOrderItem($orderSn)
+	{
+		$list = self::getAllByCondition(['orderSn' => $orderSn], null, '*');
+		return self::groupInfo($list);
+	}
 
+	//组合信息 shish 2021.3.2
+	public static function groupInfo($list)
+	{
+		if (empty($list)) {
+			return [];
+		}
+		foreach ($list as $key => $val) {
+			$cover = Yii::$app->params['imgHost'] . '/hhb_small.png';
+			if (isset($val['cover']) && !empty($val['cover'])) {
+				$cover = $cover = Yii::$app->params['imgHost'] . $val['cover'];
+			}
+			$val['cover'] = $cover;
+		}
+	}
+
+	//添加和修改花材
+	public static function replace($orderSn, $product)
+	{
+		//快速付款没有商品
+		if (empty($product)) {
+			return false;
+		}
+		self::deleteByCondition(['orderSn' => $orderSn]);
+		foreach ($product as $key => $val) {
+			$product[$key]['orderSn'] = $orderSn;
+		}
+		self::batchAdd($product);
+	}
+	
 }

+ 8 - 1
sql.sql

@@ -1297,6 +1297,13 @@ ALTER TABLE xhGhsAdminRoleAuth RENAME TO xhAdminRoleAuth;
 ALTER TABLE xhGhsAdminLog RENAME TO xhAdminLog;
 ALTER TABLE `xhAdmin` MODIFY `identity` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '身份 0未知 1客户(跳转到最近访问店铺) 2员工';
 
-=======linqh 21.03.01
+=======linqh 21-03-01
 ALTER TABLE xhItem RENAME TO xhPtItem;
 ALTER TABLE xhItemClass RENAME TO xhPtItemClass;
+
+==== shish 2021-03-02
+ALTER TABLE xhGhsOrderItem ADD unitPrice DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '单价,大单位价格' AFTER `price`;
+ALTER TABLE `xhGhsOrderItem` ADD `rank` CHAR(5) NOT NULL DEFAULT 'A' COMMENT '花材级别' AFTER `bigUnit`;
+ALTER TABLE `xhGhsOrderItem` ADD `name` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '花材名称' AFTER `id`;
+ALTER TABLE `xhGhsOrderItem` ADD cover VARCHAR(500) NOT NULL DEFAULT '' COMMENT '花材封面' AFTER `name`;
+ALTER TABLE xhGhsOrderItem ADD INDEX orderSn(`orderSn`);