Jelajahi Sumber

单据日期模块

shish 5 tahun lalu
induk
melakukan
2130bac5c6
3 mengubah file dengan 309 tambahan dan 262 penghapusan
  1. 172 162
      app/ghs/controllers/OrderController.php
  2. 126 100
      biz-ghs/order/classes/OrderClass.php
  3. 11 0
      sql.sql

+ 172 - 162
app/ghs/controllers/OrderController.php

@@ -20,166 +20,176 @@ use common\components\stringUtil;
 
 class OrderController extends BaseController
 {
-	
-	public $withoutLogin = ['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->merchantId;
-		if (isset($get['shopId'])) {
-			$shopId = $get['shopId'] ?? 0;
-			if (!empty($shopId)) {
-				$where['shopId'] = $this->shopId;
-			}
-		} else {
-			$where['shopId'] = $this->shopId;
-		}
-		$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;
-		if (!empty($shopId)) {
-			//供货商端 员工 开单
-			$post['customId'] = $post['customId'] ?? 0;
-			$post['adminId'] = $adminId;
-			$post['userId'] = 0;
-		} else {
-			//供货商端 客户 开单
-			$post['userId'] = $adminId;
-			$post['adminId'] = 0;
-			$post['customId'] = CustomClass::addCustom();
-		}
-		
-		$post['payWay'] = $this->isWx == true ? 0 : 1;
-		$post['merchantId'] = $this->merchantId;
-		$post['shopId'] = 0;
-		$post['deadline'] = time() + 1800;//订单30分钟后过期
-		$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('请选择花材');
-		}
-		$productIds = array_column($productList, 'productId');
-		ProductClass::valid($productIds, $this->merchantId);
-		$post['product'] = $productList;
-		$order = OrderClass::addOrder($post);
-		$orderSn = $order['orderSn'] ?? '';
-		$orderId = $order['id'] ?? 0;
-		util::success([
-			'orderId' => $orderId,
-			'orderSn' => $orderSn,
-			'totalPrice' => 0.01,
-			'sendType' => '快递送',
-			'sendTime' => '15:00',
-			'qrCode' => Yii::$app->params['imgHost'] . '/hhb_small.png',
-		]);
-	}
-	
-	//延期支付 shish 2021.1.19
-	public function actionDebt()
-	{
-		$get = Yii::$app->request->get();
-		$orderId = $get['orderId'] ?? 0;
-		util::complete();
-	}
-	
-	//获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
-	public function actionWxPay()
-	{
-		ini_set('date.timezone', 'Asia/Shanghai');
-		$post = Yii::$app->request->post();
-		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-		$orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
-		$order = OrderClass::getByOrderSn($orderSn);
-		$orderId = $order['id'];
-		
-		//支付前验证订单有效性
-		OrderClass::valid($order, $this->adminId);
-		
-		$name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
-		$totalFee = $order['actPrice'];
-		
-		//小程序使用miniOpenId
-		if (httpUtil::isMiniProgram()) {
-			$openId = $this->user['miniOpenId'];
-		} else {
-			$openId = $this->user['openId'];
-		}
-		$typeList = configDict::getConfig('capitalType');
-		$capitalType = $typeList['xhOrder']['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['mallHost'] . '/notice/wx-callback/');
-		$input->SetTrade_type("JSAPI");
-		
-		//花卉宝代为申请的微信支付
-		$merchantExtend = $this->merchantExtend;
-		if ($merchantExtend['wxPayApply'] == 1) {
-			$input->SetSub_openid($openId);
-		} else {
-			$input->SetOpenid($openId);
-		}
-		//小程序使用miniAppId
-		if (httpUtil::isMiniProgram()) {
-			$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-		}
-		
-		$wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-		$tools = new \JsApiPay();
-		$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-		$newParams = json_decode($jsApiParameters, true);
-		//已请求微信不能修改价格
-		$updateData = [];
-		$updateData['modPrice'] = 0;
-		if (empty($order['deadline'])) {
-			$updateData['deadline'] = $expireTime;
-		}
-		OrderService::updateById($orderId, $updateData);
-		util::success($newParams);
-	}
-	
-	//已经支付
-	public function actionHasPay()
-	{
-		util::complete();
-	}
-	
+
+    public $withoutLogin = ['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->merchantId;
+        if (isset($get['shopId'])) {
+            $shopId = $get['shopId'] ?? 0;
+            if (!empty($shopId)) {
+                $where['shopId'] = $this->shopId;
+            }
+        } else {
+            $where['shopId'] = $this->shopId;
+        }
+        $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;
+        if (!empty($shopId)) {
+            //供货商端 员工 开单
+            $post['customId'] = $post['customId'] ?? 0;
+            $post['adminId'] = $adminId;
+            $post['userId'] = 0;
+        } else {
+            //供货商端 客户 开单
+            $post['userId'] = $adminId;
+            $post['adminId'] = 0;
+            $post['customId'] = CustomClass::addCustom();
+        }
+
+        $post['payWay'] = $this->isWx == true ? 0 : 1;
+        $post['merchantId'] = $this->merchantId;
+        $post['shopId'] = 0;
+        $post['deadline'] = time() + 1800;//订单30分钟后过期
+        $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('请选择花材');
+        }
+        $productIds = array_column($productList, 'productId');
+        ProductClass::valid($productIds, $this->merchantId);
+        $post['product'] = $productList;
+        $order = OrderClass::addOrder($post);
+        $orderSn = $order['orderSn'] ?? '';
+        $orderId = $order['id'] ?? 0;
+        util::success([
+            'orderId' => $orderId,
+            'orderSn' => $orderSn,
+            'totalPrice' => 0.01,
+            'sendType' => '快递送',
+            'sendTime' => '15:00',
+            'qrCode' => Yii::$app->params['imgHost'] . '/hhb_small.png',
+        ]);
+    }
+
+    //延期支付 shish 2021.1.19
+    public function actionDebt()
+    {
+        $get = Yii::$app->request->get();
+        $orderId = $get['orderId'] ?? 0;
+        util::complete();
+    }
+
+    //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
+    public function actionWxPay()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $post = Yii::$app->request->post();
+        $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
+        $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
+        $order = OrderClass::getByOrderSn($orderSn);
+        $orderId = $order['id'];
+
+        //支付前验证订单有效性
+        OrderClass::valid($order, $this->adminId);
+
+        $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
+        $totalFee = $order['actPrice'];
+
+        //小程序使用miniOpenId
+        if (httpUtil::isMiniProgram()) {
+            $openId = $this->user['miniOpenId'];
+        } else {
+            $openId = $this->user['openId'];
+        }
+        $typeList = configDict::getConfig('capitalType');
+        $capitalType = $typeList['xhOrder']['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['mallHost'] . '/notice/wx-callback/');
+        $input->SetTrade_type("JSAPI");
+
+        //花卉宝代为申请的微信支付
+        $merchantExtend = $this->merchantExtend;
+        if ($merchantExtend['wxPayApply'] == 1) {
+            $input->SetSub_openid($openId);
+        } else {
+            $input->SetOpenid($openId);
+        }
+        //小程序使用miniAppId
+        if (httpUtil::isMiniProgram()) {
+            $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+        }
+
+        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+        $tools = new \JsApiPay();
+        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+        $newParams = json_decode($jsApiParameters, true);
+        //已请求微信不能修改价格
+        $updateData = [];
+        $updateData['modPrice'] = 0;
+        if (empty($order['deadline'])) {
+            $updateData['deadline'] = $expireTime;
+        }
+        OrderService::updateById($orderId, $updateData);
+        util::success($newParams);
+    }
+
+    //已经支付
+    public function actionHasPay()
+    {
+        util::complete();
+    }
+
+    //获取订单详情 shish 2021.1.21
+    public function actionDetail()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $info = OrderClass::getOrderInfo($id, true, true);
+        OrderClass::valid($info, $this->shopId);
+        util::success($info);
+    }
+
 }

+ 126 - 100
biz-ghs/order/classes/OrderClass.php

@@ -8,109 +8,135 @@ use bizGhs\custom\classes\CustomClass;
 use bizGhs\stat\classes\StatOrderCountClass;
 use common\components\orderSn;
 use common\components\stringUtil;
+use common\components\util;
 use Yii;
 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_OTHER = 4;
-	
-	//添加订单 shish 2019.12.5
-	public static function addOrder($data)
-	{
-		$date = date("Y-m-d H:i:s");
-		$merchantId = $data['merchantId'] ?? 0;
-		$month = date("Ym");
-		$data['orderSn'] = orderSn::getGhsOrderSn();
-		$data['payStatus'] = 0;
-		$data['createTime'] = $date;
-		$data['addTime'] = time();
-		
-		//花材列表
-		$product = $data['product'];
-		OrderItemClass::batchAdd($product);
-		
-		//将花店每月的总订单数作为编号
-		$riseNum = StatOrderCountClass::addOrder($month, $merchantId);
-		$data['sendNum'] = $riseNum;
-		$data['num'] = 1;
-		$data['smallNum'] = 1;
-		$return = self::add($data);
-		
-		//全部订单+1,待付款订单+1
-		$merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
-		$merchantAsset->unPayOrder += 1;
-		$merchantAsset->totalOrder += 1;
-		$merchantAsset->save();
-		
-		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);
-		return $data;
-	}
-	
-	//整合订单员工和供货商等信息 shish 2021.1.19
-	public static function groupOrder($list, $showButton = false, $showProgress = 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'] ?? '';
-			if ($showButton) {
-				$list[$key]['buttonList'] = [
-					['type' => 'item', 'show' => 1, 'status' => 0],
-					['type' => 'send', 'show' => 1, 'status' => 1],
-					['type' => 'selfGet', 'show' => 1, 'status' => 1],
-				];
-			}
-		}
-		return $list;
-	}
-	
+
+    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_OTHER = 4;
+
+    //添加订单 shish 2019.12.5
+    public static function addOrder($data)
+    {
+        $date = date("Y-m-d H:i:s");
+        $merchantId = $data['merchantId'] ?? 0;
+        $month = date("Ym");
+        $data['orderSn'] = orderSn::getGhsOrderSn();
+        $data['payStatus'] = 0;
+        $data['createTime'] = $date;
+        $data['addTime'] = time();
+
+        //花材列表
+        $product = $data['product'];
+        OrderItemClass::batchAdd($product);
+
+        //将花店每月的总订单数作为编号
+        $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
+        $data['sendNum'] = $riseNum;
+        $data['num'] = 1;
+        $data['smallNum'] = 1;
+        $return = self::add($data);
+
+        //全部订单+1,待付款订单+1
+        $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
+        $merchantAsset->unPayOrder += 1;
+        $merchantAsset->totalOrder += 1;
+        $merchantAsset->save();
+
+        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);
+        return $data;
+    }
+
+    //整合订单员工和供货商等信息 shish 2021.1.19
+    public static function groupOrder($list, $showButton = false, $showProgress = 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'] ?? '';
+            if ($showButton) {
+                $list[$key]['buttonList'] = [
+                    ['type' => 'item', 'show' => 1, 'disable' => 1],
+                    ['type' => 'send', 'show' => 1, 'disable' => 0],
+                    ['type' => 'selfGet', 'show' => 1, 'disable' => 0],
+                ];
+            }
+            if ($showProgress) {
+                $list[$key]['progress'] = [
+                    ['name' => '创建', 'complete' => 1],
+                    ['name' => '待确认', 'complete' => 0],
+                    ['name' => '出库', 'complete' => 0],
+                ];
+            }
+        }
+        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)
+    {
+        $info = self::getById($id);
+        $respond = self::groupOrder([$info], true, true);
+        return current($respond);
+    }
+
 }

+ 11 - 0
sql.sql

@@ -773,4 +773,15 @@ AUTO_INCREMENT=30;
 ALTER TABLE `xhGhsPurchaseOrder`
 MODIFY COLUMN `entryTime`  timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入库时间' AFTER `orderPrice`;
 
+=====
+== shish 2021-1-21
+ALTER TABLE xhGhsOrder DROP COLUMN `payTime`;
+ALTER TABLE xhGhsOrder ADD `payTime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '付款时间' AFTER `deadline`;
+
+ALTER TABLE xhGhsOrder DROP COLUMN `deadline`;
+ALTER TABLE xhGhsOrder ADD `deadline` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '订单有效时间' AFTER `status`;
+
+ALTER TABLE xhGhsOrder DROP COLUMN `sendTime`;
+ALTER TABLE xhGhsOrder ADD `sendTime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '配送时间' AFTER `sendSide`;
+