Browse Source

客户的花店

shish 4 năm trước cách đây
mục cha
commit
62aec5552a

+ 39 - 4
app-hd/controllers/OrderController.php

@@ -7,6 +7,7 @@ use biz\sj\services\MerchantExtendService;
 use biz\sj\services\MerchantService;
 use bizGhs\product\classes\ProductClass;
 use bizHd\custom\classes\CustomClass;
+use bizHd\goods\classes\GoodsClass;
 use bizHd\merchant\services\ShopService;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\OrderSendClass;
@@ -32,7 +33,7 @@ class OrderController extends BaseController
 
     public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
 
-    //开单操作 ssh 2019.12.3
+    //开单操作 ssh 20220316
     public function actionCreateOrder()
     {
         $post = Yii::$app->request->post();
@@ -45,11 +46,45 @@ class OrderController extends BaseController
         $post['deadline'] = $expireTime;
         //商城
         $post['fromType'] = 1;
+        //客户
+        $customId = $post['customId'] ?? 0;
+        if (empty($customId)) {
+            $customId = isset($this->shop->skCustomId) ? $this->shop->skCustomId : 0;
+        }
+        if (empty($customId)) {
+            util::fail('没有找到客户');
+        }
+        $custom = CustomClass::getById($customId);
+        if (empty($custom)) {
+            util::fail('没有找到客户哦');
+        }
+        $post['customId'] = $customId;
 
-//        $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
-//        OrderClass::staffKdPay($payWay, $orderSn);
+        $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
 
-//        util::success(['orderSn' => $orderSn, 'totalPrice' => $currentPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
+        $productJson = $post['product'] ?? '';
+        if (empty($productJson)) {
+            util::fail('请选择商品');
+        }
+        $productList = json_decode($productJson, true);
+        if (empty($productList)) {
+            util::fail('请选择商品');
+        }
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            //批量验证商品
+            GoodsClass::batchValid($productList, $this->mainId);
+            $post['product'] = $productList;
+            $post['deadline'] = date("Y-m-d H:i:s", strtotime('+360 day'));
+            $return = OrderService::createFinishOrder($post, $custom, $hasPay);
+            $transaction->commit();
+            util::success($return);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("下单失败原因:" . $e->getMessage());
+            util::fail('下单失败');
+        }
 
     }
 

+ 3 - 11
biz-hd/order/classes/OrderClass.php

@@ -71,27 +71,19 @@ class OrderClass extends BaseClass
         $data['orderSn'] = orderSn::getOrderSn();
         $data['payStatus'] = 0;
         $shopId = $data['shopId'] ?? 0;
+
         //累计订单增加
-        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
+        $shop = ShopClass::getLockById($shopId);
         $shop->unPayOrder += 1;
         $shop->totalOrder += 1;
         $shop->save();
+
         //将花店每月的总订单数作为编号
         $riseNum = StatOrderCountClass::addOrder($shop);
         $data['sendNum'] = date("d") . $riseNum;
         $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
         $return = self::add($data);
 
-        //员工业绩、总业绩增加
-        $shopAdminId = $return['shopAdminId'] ?? 0;
-        if (!empty($shopAdminId)) {
-            $amount = $return['actPrice'] ?? 0.00;
-            $shopAdmin = ShopAdminClass::getById($shopAdminId, true);
-            $shopAdmin->kdAmount = bcadd($shopAdmin->kdAmount, $amount, 2);
-            $shopAdmin->save();
-        }
-        StatYjClass::addYj($return);
-
         return $return;
     }
 

+ 27 - 0
biz-hd/order/services/OrderService.php

@@ -12,6 +12,7 @@ use bizHd\promote\services\CouponRightService;
 use bizHd\promote\services\CouponService;
 use bizHd\user\classes\UserAssetClass;
 use bizHd\user\services\UserService;
+use common\components\dict;
 use common\components\error;
 use common\components\imgUtil;
 use common\components\stringUtil;
@@ -25,6 +26,32 @@ class OrderService extends BaseService
 
     public static $baseFile = '\bizHd\order\classes\OrderClass';
 
+    public static function createFinishOrder($data, $custom, $hasPay = 1)
+    {
+        $payWay = $data['payWay'] ?? dict::getDict('payWay', 'wxPay');
+
+        $returnOrder = OrderClass::addOrder($data);
+
+        $mallData = [
+
+        ];
+        $purchase = \bizMall\order\classes\OrderClass::addOrder($mallData);
+
+        //欠款和已付款的直接完成
+        if (in_array($hasPay, [dict::getDict('hasPay', 'payed'), dict::getDict('hasPay', 'debt')])) {
+            //顺序不能换
+            \bizMall\order\services\OrderService::payAfter($purchase, $payWay);
+            self::payAfter($returnOrder, $payWay);
+        }
+
+        return $returnOrder;
+    }
+
+    public static function payAfter($order, $payWay)
+    {
+
+    }
+
     //添加订单
     public static function addOrder($data)
     {

+ 5 - 0
biz-mall/order/services/OrderService.php

@@ -17,6 +17,11 @@ class OrderService extends BaseService
 
     public static $baseFile = '\bizMall\order\classes\OrderClass';
 
+    public static function payAfter($order, $payWay)
+    {
+
+    }
+
     //获取订单信息 ssh 2019.11.28
     public static function getOrderList($where)
     {

+ 35 - 1
sql.txt

@@ -312,7 +312,6 @@ ALTER TABLE xhGoods CHANGE `goodsName` `name` VARCHAR(100) NOT NULL DEFAULT '' C
 ============ 批发零售绑定关系 shish 20220314
 
 
-
 ========================花材相关表结构变更start=======linqh 20220315=================
 ALTER TABLE `xhGhsItem`
 ADD COLUMN `mainId`  int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`,
@@ -321,3 +320,38 @@ ADD INDEX `idx_mainId` (`mainId`) ;
 
 
 ===============花材相关表结构变更end========
+
+
+==========客户的花店 shish 20220316
+
+DROP TABLE IF EXISTS `xhHd`;
+CREATE TABLE `xhHd` (
+  `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+  `userId` INT NOT NULL DEFAULT 0 COMMENT '用户id',
+  `sjId` INT NOT NULL DEFAULT 0 COMMENT '商家id',
+  `shopId` INT NOT NULL DEFAULT 0 COMMENT '门店id',
+  `avatar` VARCHAR(800) NOT NULL DEFAULT '' COMMENT '头像',
+  `name` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '供货商名称',
+  `py` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '名称拼音首字母',
+  `mobile` CHAR(15) NOT NULL DEFAULT '' COMMENT '手机号',
+  `province` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '省',
+  `city` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '市',
+  `dist` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '区县',
+  `address` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '街道地址',
+  `floor` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '楼号门牌号',
+  `fullAddress` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '完整地址',
+  `showAddress` VARCHAR(900) NOT NULL DEFAULT '' COMMENT '地图接口显示的完整地址',
+  `lat` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '纬度',
+  `long` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '经度',
+  `debt` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '1没有欠款 2有欠款',
+  `debtNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '欠款订单数,欠款笔数',
+  `debtAmount` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '欠款金额',
+  `giveLevel` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '客户等级',
+  `giveDiscount` DECIMAL(3,2) NOT NULL DEFAULT '1.00' COMMENT '提供的折扣',
+  `expendAmount` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '消费金额',
+  `expendNum` INT(11) NOT NULL DEFAULT '0' COMMENT '消费次数',
+  `black` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '列入黑名单 1没有 2是',
+  `inTurn` INT(10) NOT NULL DEFAULT '100' COMMENT '排序',
+  `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间'
+) COMMENT='客户的花店';