Browse Source

红包功能实现

shizhongqi 6 tháng trước cách đây
mục cha
commit
b7baf52ab0

+ 182 - 1
app-hd/controllers/HbController.php

@@ -6,12 +6,14 @@ use biz\ghs\classes\GhsClass;
 use biz\market\classes\XrFlClass;
 use biz\shop\classes\ShopClass;
 use bizGhs\custom\classes\CustomClass;
+use bizHd\hb\classes\HbManageClass;
+use bizHd\recharge\classes\RechargeShbClass;
 use common\components\util;
+use bizHd\hb\classes\HbClass;
 use Yii;
 
 class HbController extends BaseController
 {
-
     public $guestAccess = [];
 
     //获取新人红包福利 ssh 20211026
@@ -40,4 +42,183 @@ class HbController extends BaseController
         util::complete('领取成功');
     }
 
+    /**
+     * 获取红包列表
+     */
+    public function actionHbList()
+    {
+        $where = ['shopId' => $this->shopId];
+        $customId = Yii::$app->request->get('customId', '');
+        if (!empty($customId)) {
+            $where['customId'] = $customId;
+        }
+        $status = Yii::$app->request->get('status', '');
+        if (isset($status) && $status != '') {
+            if($status == -1){ // 已失效包含:1作废 与 过期(0未使用但endTime<当前时间) --- 所以当操作作废时,status改为-1,同时将endTime改为当前时间
+                $where['endTime<'] = time();
+            }else{
+                $where['status'] = $status;
+            }
+        }
+        $list = HbClass::getList('*', $where, 'id desc', 'custom');
+        if (!empty($list['list'])) {
+            foreach ($list['list'] as &$v) {
+                $v['customName'] = $v['custom']['name'];
+            }
+        }
+        util::success($list);
+    }
+
+    // 单个门店下所有可用红包
+    public function actionAvailableHb()
+    {
+        $get = Yii::$app->request->get();
+        
+        $where = [];
+        $where['customId'] = $get['customId'];
+        $where['status'] = 0;
+        $where['endTime>'] = time();
+
+        $list = HbClass::getAllByCondition($where, 'id DESC');
+        util::success($list);
+    }
+
+    /**
+     * 获取红包详情
+     */
+    public function actionHbDetail()
+    {
+        $hbId = Yii::$app->request->get('hbId');
+        $hb = HbClass::getById($hbId);
+        util::success($hb);
+    }
+
+    /**
+     * 创建红包
+     */
+    public function actionCreateHb()
+    {
+        // TODO
+        // $form = new \hd\models\hb\CreateHbForm();
+        // $form->load(Yii::$app->request->post(), '');
+        // if (!$form->validateForm()) {
+        //     return;
+        // }
+        // $data = $form->attributes;
+        $post = Yii::$app->request->post();
+
+        $duration = intval($post['days']);
+        $count = $post['count'] ?? 1;
+        $beginTime = time();
+        $endTime = $beginTime + $duration * 86400;
+
+        $data = [
+            'mainId' => $this->mainId,
+            'shopId' => $this->shopId,
+            'userId' => $post['userId'],
+            'customId' => $post['customId'],
+            'amount' => $post['amount'],
+            'minConsume' => $post['minConsume'],
+            'beginTime' => $beginTime,
+            'endTime' => $endTime,
+            'willTime' => $endTime,
+            'duration' => $duration,
+            'getType' => 1, //取得方式 0新人领取 1门店发放 2充值赠送
+            'remark' => $post['remark'],
+        ];
+
+        $manageData = [
+            'getType' => 1, //取得方式 0新人领取 1门店发放 2充值赠送
+            'getTargetId' => 0,
+            'createStaffId' => $this->shopAdminId,
+            'createStaffName' => $this->shopAdminName,
+            'remark' => $data['remark'],
+        ];
+        for ($i = 0; $i < $count; $i++) {
+            $hb = HbClass::add($data);
+
+            $manageData['hbId'] = $hb['id'];
+            $hbManage = HbManageClass::add($manageData);
+        }
+        $arr = [];
+        if(!empty($hb) && !empty($hbManage)){
+            $arr = array_merge($hb, $hbManage);
+        }
+        util::success($arr);
+    }
+
+    /**
+     * 更新红包
+     */
+    public function actionUpdateHb()
+    {
+        // TODO
+        // $hbId = Yii::$app->request->get('hbId');
+        // $form = new \hd\models\hb\UpdateHbForm();
+        // $form->load(Yii::$app->request->post(), '');
+        // if (!$form->validateForm()) {
+        //     return;
+        // }
+        // $data = $form->attributes;
+        $data = Yii::$app->request->post();
+        $id = $data['id'];
+        $hb = HbClass::getById($id, true);
+
+        //检测是否是本门店的红包
+        if($hb->shopId != $this->shopId){
+            util::fail('不是本门店的红包');
+        }
+
+        foreach($data as $key => $val){
+            $hb->$key = $val;
+        }
+        // 当操作作废时,status改为-1,同时将endTime改为当前时间
+        if($hb->status == -1){
+            $hb->endTime = time();
+            //记录作废人
+            $updateData = [
+                'cancelStaffId' => $this->shopAdminId,
+                'cancelStaffName' => $this->shopAdminName,
+                'cancelTime' => date('Y-m-d H:i:s'),
+            ];
+            HbManageClass::updateByCondition(['hbId'=>$id], $updateData);
+        }
+        $hb->save();
+        util::success($hb->attributes);
+    }
+
+    /**
+     * 充值送红包规则列表
+     */
+    public function actionHbRules()
+    {
+        $list = RechargeShbClass::getList('*', ['shopId'=>$this->shopId]);
+        util::success($list);
+    }
+
+    /**
+     * 充值送红包规则创建
+     */
+    public function actionSendHbRules()
+    {
+        $data = Yii::$app->request->post();
+        //var_dump($data); die;
+        $hbRules = RechargeShbClass::setRules($this->shopId, $this->mainId, $data);
+        util::success($hbRules);
+    }
+
+    /**
+     *
+     */
+    public function actionDeleteHbRule()
+    {
+        $id = Yii::$app->request->post('id');
+        var_dump($id); die;
+        $re = RechargeShbClass::deleteById($id);
+        if($re == 1){
+            util::complete();
+        }else{
+            util::fail('删除失败');
+        }
+    }
 }

+ 14 - 0
app-hd/controllers/RefundController.php

@@ -4,6 +4,7 @@ namespace hd\controllers;
 
 use biz\shop\classes\ShopExtClass;
 use bizHd\custom\classes\CustomClass;
+use bizHd\hb\classes\HbClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\OrderGoodsClass;
 use bizHd\order\classes\OrderItemClass;
@@ -263,6 +264,19 @@ class RefundController extends BaseController
             }
             $transaction->commit();
 
+            //红包退款
+            $refundHb = $post['refundHb'] ?? 0;
+            $hbId = $order->hbId;
+            if ($refundHb == 1 && $hbId != 0 && bccomp($post['price'], $order->orderPrice, 2) == 0) {
+                $hb = HbClass::getById($hbId, true);
+                if (empty($hb)) {
+                    util::fail('没有找到红包');
+                }
+                $hb->status = 0;
+                $hb->orderId = 0;
+                $hb->save();
+            }
+
             //制作单取消通知
             $shopId = $this->shopId ?? 0;
             $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);

+ 5 - 3
app-hd/models/order/CreateOrderForm.php

@@ -43,6 +43,8 @@ class CreateOrderForm extends BaseForm
     public $weight;
     public $deliveryRemark;
     public $needPrint;
+    public $hbId;
+    public $hbAmount;
     
     // Common order fields
     public $remark;
@@ -64,9 +66,9 @@ class CreateOrderForm extends BaseForm
             [['zjGathering'], 'validateZjGathering'],
             [['unitGoodsPrice'], 'validateUnitGoodsPrice'],
             [['product'], 'validateProduct'],
-            
-            [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'forward', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity', 'needPrint'], 'integer'],
-            [['modifyPrice', 'lsGoodsPrice', 'dealPrice', 'deliveryPrice', 'deliveryDistance', 'weight'], 'number'],
+
+            [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'forward', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity',  'needPrint', 'hbId'], 'integer'],
+            [['modifyPrice', 'lsGoodsPrice', 'dealPrice', 'deliveryPrice', 'deliveryDistance', 'weight', 'hbAmount'], 'number'],
             [['shopAdminName', 'getStaffName', 'bookName', 'receiveMobile', 'bookMobile', 'historyDate', 'product', 'deliveryPlatform', 'deliveryBracketContent', 'pickupTime', 'remark', 'deliveryRemark', 'reachDate', 'reachPeriod', 'cardInfo'], 'string'],
             [['unitGoodsPrice', 'deliveryAllParams'], 'safe'],
         ];

+ 26 - 9
app-mall/controllers/HbController.php

@@ -1,24 +1,41 @@
 <?php
-
 namespace mall\controllers;
 
-use bizMall\promote\services\CouponService;
 use Yii;
 use common\components\util;
+use bizHd\hb\classes\HbClass;
 
 class HbController extends BaseController
 {
-
 	//优惠券列表 ssh 2019.12.11
 	public function actionList()
 	{
 		$get = Yii::$app->request->get();
-        $list = [
-            ['amount'=>100,'miniCost'=>200,'deadline'=>time(),'status'=>1],
-            ['amount'=>100,'miniCost'=>200,'deadline'=>time(),'status'=>0],
-            ['amount'=>100,'miniCost'=>200,'deadline'=>time(),'status'=>2],
-        ];
-		util::success(['list'=>$list]);
+        $where = [];
+		$where['t.userId'] = $this->userId;
+		if (isset($get['status'])) {
+			if($get['status'] == 3){
+				// 全部状态
+			}elseif($get['status'] == 2){ // 已失效包含:1作废 与 过期(0未使用但endTime<当前时间) --- 所以当操作作废时,status改为-1,同时将endTime改为当前时间
+				$where['t.endTime<'] = time();
+			} else {
+				$where['t.status'] = $get['status'];
+			}
+		}
+		
+        $list = HbClass::getHbList(['t.*', 's.merchantName', 's.shopName'], $where);
+		util::success($list);
 	}
 
+	// 单个门店下所有可用红包
+	public function actionAvailableHb()
+    {
+        $where = [];
+        $where['customId'] = $this->customId;
+        $where['status'] = 0;
+        $where['endTime>'] = time();
+
+        $list = HbClass::getAllByCondition($where, 'id DESC');
+        util::success($list);
+    }
 }

+ 3 - 2
app-mall/controllers/OrderController.php

@@ -331,8 +331,8 @@ class OrderController extends BaseController
                 if (empty($post['long']) || empty($post['lat'])) {
                     util::fail('位置错误');
                 }
-                $originalLng = doubleval($post['long']);
-                $originalLat = doubleval($post['lat']);
+                // $originalLng = doubleval($post['long']);
+                // $originalLat = doubleval($post['lat']);
                 // $city = $post['city'] ?? '';
                 // $dist = $post['dist'] ?? '';
                 // $address = $post['address'] ?? '';
@@ -430,6 +430,7 @@ class OrderController extends BaseController
                 }
             }
             $transaction->commit();
+            
             $orderSn = $return->orderSn ?? '';
             $orderPrice = $return->orderPrice ?? 0;
             $id = $return->id ?? 0;

+ 0 - 2
biz-hd/base/classes/BaseClass.php

@@ -2,11 +2,9 @@
 
 namespace bizHd\base\classes;
 
-use Yii;
 use common\components\imgUtil;
 class BaseClass extends \common\base\classes\BaseClass
 {
-
     //组合图片
     public static function groupImg($img)
     {

+ 55 - 0
biz-hd/hb/classes/HbClass.php

@@ -0,0 +1,55 @@
+<?php
+namespace bizHd\hb\classes;
+
+use bizHd\base\classes\BaseClass;
+use bizHd\hb\models\Hb;
+use common\components\util;
+use Yii;
+
+class HbClass extends BaseClass
+{
+	public static $baseFile = Hb::class;
+
+    public static function getHbList($select, $where)
+    {
+        $get = Yii::$app->request->get();
+        $page = isset($get['page']) ? $get['page'] : 1;
+        $pageSize = isset($get['pageSize']) && !empty($get['pageSize']) ? $get['pageSize'] : Yii::$app->params['pageSize'];
+        $offset = ($page - 1) * $pageSize;
+
+        $model = self::getModel();
+        $query = $model->conditionQuery($where)->alias('t');
+        $query->joinWith(['shop' => function($q) {
+            $q->alias('s');
+        }]);
+        $query->select($select);
+
+        $clone = clone $query;
+        $count = $clone->count();
+        $totalPage = ceil($count / $pageSize);
+        $data['totalNum'] = $count;
+        $data['totalPage'] = $totalPage;
+        $data['moreData'] = $totalPage > $page ? 1 : 0;
+        
+        $list = $query->offset($offset)->limit($pageSize)->orderBy('t.createdAt DESC')->asArray()->all();
+        $data['list'] = $list;
+
+        return $data;
+    }
+
+    /**
+     * 红包退回
+     * @param $id
+     */
+    public static function hbBack($id)
+    {
+        $hb = self::getById($id, true);
+        if (empty($hb)) {
+            Yii::error('没有找到红包', __METHOD__);
+            util::fail('没有找到红包');
+        }
+        $hb->status = 0;
+        $hb->orderId = 0;
+        $hb->save();
+    }
+}

+ 10 - 0
biz-hd/hb/classes/HbManageClass.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizHd\hb\classes;
+
+use bizHd\base\classes\BaseClass;
+use bizHd\hb\models\HbManage;
+
+class HbManageClass extends BaseClass
+{
+	public static $baseFile = HbManage::class;
+}

+ 23 - 0
biz-hd/hb/models/Hb.php

@@ -0,0 +1,23 @@
+<?php
+namespace bizHd\hb\models;
+use bizHd\base\models\Base;
+use bizHd\custom\models\Custom;
+use bizHd\shop\models\Shop;
+
+class Hb extends Base
+{
+	public static function tableName()
+	{
+		return 'xhHb';
+	}
+
+    public function getCustom()
+    {
+        return $this->hasOne(Custom::class, ['id' => 'customId']);
+    }
+
+    public function getShop()
+    {
+        return $this->hasOne(Shop::class, ['id' => 'shopId']);
+    }
+}

+ 11 - 0
biz-hd/hb/models/HbManage.php

@@ -0,0 +1,11 @@
+<?php
+namespace bizHd\hb\models;
+use bizHd\base\models\Base;
+
+class HbManage extends Base
+{
+	public static function tableName()
+	{
+		return 'xhHbManage';
+	}
+}

+ 7 - 3
biz-hd/order/services/OrderService.php

@@ -8,9 +8,7 @@ use biz\sj\services\SjCapitalService;
 use biz\sj\services\MerchantService;
 use bizHd\custom\classes\CustomClass;
 use bizHd\goods\classes\GoodsClass;
-use bizHd\group\classes\GroupClass;
-use bizHd\group\classes\GroupGoodsClass;
-use bizHd\group\classes\GroupItemClass;
+use bizHd\hb\classes\HbClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\OrderGoodsClass;
 use bizHd\order\classes\OrderItemClass;
@@ -304,6 +302,12 @@ class OrderService extends BaseService
         //保存订单
         $returnOrder = OrderClass::addOrder($data);
 
+        //如果 $data['hbId'] 不为空,则把红包消费掉
+        if(isset($data['hbId']) && $data['hbId'] != 0){
+            $hbId = $data['hbId'];
+            HbClass::hbBack($hbId);
+        }
+
         //欠款、已付款、余额支付的直接完成,另外客服下的单要走配送流程,所以是待配送状态
         if (in_array($hasPay, [dict::getDict('hasPay', 'payed'), dict::getDict('hasPay', 'debt'), dict::getDict('hasPay', 'balance')])) {
             $params = [];

+ 61 - 0
biz-hd/recharge/classes/RechargeShbClass.php

@@ -10,4 +10,65 @@ class RechargeShbClass extends BaseClass
 
     public static $baseFile = '\bizHd\recharge\models\RechargeShb';
 
+    /**
+     * 设置充值送红包规则
+     * @param int $shopId
+     * @param int $mainId
+     * @param array $data
+     * @return array
+     */
+    public static function setRules($shopId, $mainId, $data)
+    {
+        // 1. 删除旧规则
+        // self::deleteByCondition(['shopId' => $shopId]);
+
+        if (empty($data)) {
+            return [];
+        }
+
+        $updateRows = [];
+        $createRows = [];
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            foreach ($data as $item) {
+                if ($item['id'] == '') {
+                    $createRows[] = [
+                        'shopId' => $shopId,
+                        'mainId' => $mainId,
+                        'amount' => $item['amount'],
+                        'hbAmount' => $item['hbAmount'],
+                        'num' => $item['num'] ?? 1,
+                        'miniCost' => $item['miniCost'] ?? 0, //最低消费金额,0表示没有要求
+                        'duration' => $item['duration'] == 0 ? 0 :$item['duration'], //0表示永不过期
+                    ];
+                } else {
+                    $row = [
+                        'shopId' => $shopId,
+                        'mainId' => $mainId,
+                        'amount' => $item['amount'],
+                        'hbAmount' => $item['hbAmount'],
+                        'num' => $item['num'] ?? 1,
+                        'miniCost' => $item['miniCost'] ?? 0, //最低消费金额,0表示没有要求
+                        'duration' => $item['duration'] == 0 ? 0 :$item['duration'], //0表示永不过期
+                    ];
+                    self::updateById($item['id'], $row);
+                    $updateRows[] = $row;
+                }
+            }
+
+            if (!empty($createRows)) {
+                self::batchAdd($createRows);
+            }
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            YII::error('RechargeShbClass::setRules error: ' . $e->getMessage());
+            throw $e;
+        }
+
+        return ['createRows' => $createRows, 'updateRows' => $updateRows];
+    }
+
 }

+ 26 - 10
common/base/classes/BaseClass.php

@@ -4,6 +4,8 @@ namespace common\base\classes;
 
 use Yii;
 use \common\base\models\Base;
+use yii\base\InvalidConfigException;
+use yii\db\ActiveRecord;
 
 class BaseClass
 {
@@ -11,8 +13,8 @@ class BaseClass
 
     /**
      * 获取模型对象
-     * @return Base|\yii\db\ActiveRecord
-     * @throws \yii\base\InvalidConfigException
+     * @return Base|ActiveRecord
+     * @throws InvalidConfigException
      */
     protected static function getModel()
     {
@@ -25,14 +27,15 @@ class BaseClass
         }
 
         // 未设置 $baseFile,配置不完整
-        throw new \yii\base\InvalidConfigException(
+        throw new InvalidConfigException(
             'Missing model binding for ' . static::class . ': set static $baseFile.'
         );
     }
 
     /**
      * 获取模型对象 (ActiveRecord)
-     * @return \yii\db\ActiveRecord
+     * @return ActiveRecord
+     * @throws InvalidConfigException
      */
     public static function getActiveRecord()
     {
@@ -121,6 +124,7 @@ class BaseClass
      * 根据主键ID删除一条记录
      * @param int|string $id 主键ID
      * @return int|false 删除的行数,失败返回false
+     * @throws InvalidConfigException
      * @throws \Throwable
      * @throws \yii\db\StaleObjectException
      */
@@ -160,6 +164,7 @@ class BaseClass
      * @param int|string $id 主键ID
      * @param array $data 更新的数据
      * @return array ['status' => bool, 'data' => array]
+     * @throws \Exception
      */
     public static function updateById($id, $data)
     {
@@ -172,6 +177,7 @@ class BaseClass
      * @param array $ids 主键ID数组
      * @param array $data 更新的数据
      * @return int 更新的行数
+     * @throws \Exception
      */
     public static function updateByIds($ids, $data)
     {
@@ -184,6 +190,7 @@ class BaseClass
      * @param array $condition 查询条件
      * @param array $data 更新的数据
      * @return int 更新的行数
+     * @throws \Exception
      */
     public static function updateByCondition($condition, $data)
     {
@@ -197,7 +204,8 @@ class BaseClass
      * @param int|string $id 主键ID
      * @param bool $returnObject 是否返回对象
      * @param string|array $field 查询字段
-     * @return array|\yii\db\ActiveRecord|null
+     * @return array|ActiveRecord|null
+     * @throws \Exception
      */
     public static function getById($id, $returnObject = false, $field = '*')
     {
@@ -210,7 +218,8 @@ class BaseClass
      * @param bool $returnObject 是否返回对象
      * @param string|array|bool $order 排序
      * @param string|array $field 查询字段
-     * @return array|\yii\db\ActiveRecord|null
+     * @return array|ActiveRecord|null
+     * @throws \Exception
      */
     public static function getOne($returnObject = false, $order = false, $field = '*')
     {
@@ -224,7 +233,8 @@ class BaseClass
      * @param bool $returnObject 是否返回对象
      * @param string|array|bool $order 排序
      * @param string|array $field 查询字段
-     * @return array|\yii\db\ActiveRecord|null
+     * @return array|ActiveRecord|null
+     * @throws \Exception
      */
     public static function getByCondition($condition, $returnObject = false, $order = false, $field = '*')
     {
@@ -236,7 +246,7 @@ class BaseClass
      * 判断数据是否存在
      * @param array $condition 查询条件
      * @return bool
-     * @throws \yii\base\InvalidConfigException
+     * @throws \Exception
      */
     public static function exists($condition)
     {
@@ -251,7 +261,8 @@ class BaseClass
      * @param string|array $field 查询字段
      * @param string|callable|null $indexBy 索引字段
      * @param bool $returnObject 是否返回对象
-     * @return array|\yii\db\ActiveRecord[]
+     * @return array|ActiveRecord[]
+     * @throws \Exception
      */
     public static function getAllByCondition($condition, $order = null, $field = '*', $indexBy = null, $returnObject = false)
     {
@@ -266,6 +277,7 @@ class BaseClass
      * @param string|callable|null $indexBy 索引字段
      * @param string|array $field 查询字段
      * @return array
+     * @throws \Exception
      */
     public static function getByIds($ids, $order = null, $indexBy = null, $field = '*')
     {
@@ -277,6 +289,7 @@ class BaseClass
      * 根据条件获取记录数量
      * @param array $condition 查询条件
      * @return int|string
+     * @throws \Exception
      */
     public static function getCount($condition)
     {
@@ -290,6 +303,7 @@ class BaseClass
      * @param array $condition 更新条件
      * @param array $params 绑定参数
      * @return int 更新行数
+     * @throws \Exception
      */
     public static function counters($counters, $condition, $params = [])
     {
@@ -301,7 +315,8 @@ class BaseClass
      * 根据主键获取记录并锁定 (SELECT FOR UPDATE)
      * @param int|string $id 主键ID
      * @param string|array $field 查询字段
-     * @return array|\yii\db\ActiveRecord|null
+     * @return array|ActiveRecord|null
+     * @throws \Exception
      */
     public static function getLockById($id, $field = '*')
     {
@@ -314,6 +329,7 @@ class BaseClass
      * @param array $condition 查询条件
      * @param string $field 求和字段
      * @return mixed
+     *  @throws \Exception
      */
     public static function sum($condition, $field)
     {

+ 12 - 7
common/base/models/Base.php

@@ -50,13 +50,6 @@ class Base extends ActiveRecord
         }
 
         return $returnObject ? $model : $model->attributes;
-
-        // 原有实现无异常处理
-        // $model->save();
-        // if ($returnObject) {
-        //     return $model;
-        // }
-        // return $model->attributes;
     }
 
     /**
@@ -192,6 +185,7 @@ class Base extends ActiveRecord
      * @param bool $returnObject 是否返回对象
      * @param string|array $field 查询字段
      * @return array|ActiveRecord|null
+     * @throws \Exception
      */
     public function getById($id, $returnObject = false, $field = '*')
     {
@@ -210,6 +204,7 @@ class Base extends ActiveRecord
      * @param string|array|bool $order 排序
      * @param string|array $field 查询字段
      * @return array|ActiveRecord|null
+     * @throws \Exception
      */
     public function getByCondition($condition, $returnObject = false, $order = false, $field = '*')
     {
@@ -226,6 +221,7 @@ class Base extends ActiveRecord
      * @param string|array|bool $order 排序
      * @param string|array $field 查询字段
      * @return array|ActiveRecord|null
+     * @throws \Exception
      */
     public function getOne($returnObject = false, $order = false, $field = '*')
     {
@@ -251,6 +247,7 @@ class Base extends ActiveRecord
      * ];
      * @param array $condition 查询条件数组
      * @return \yii\db\ActiveQuery
+     * @throws \Exception
      */
     public function conditionQuery($condition = [])
     {
@@ -307,6 +304,7 @@ class Base extends ActiveRecord
      * 判断数据是否存在
      * @param array $condition 查询条件
      * @return bool
+     * @throws \Exception
      */
     public function exists($condition)
     {
@@ -321,6 +319,7 @@ class Base extends ActiveRecord
      * @param string|callable|null $indexBy 索引字段
      * @param bool $returnObject 是否返回对象
      * @return array|ActiveRecord[]
+     * @throws \Exception
      */
     public function getAllByCondition($condition, $order = null, $field, $indexBy = null, $returnObject = false)
     {
@@ -346,6 +345,7 @@ class Base extends ActiveRecord
      * @param string|callable|null $indexBy 索引字段
      * @param string|array $field 查询字段
      * @return array
+     * @throws \Exception
      */
     public function getByIds($ids, $order = null, $indexBy = null, $field = '*')
     {
@@ -368,6 +368,7 @@ class Base extends ActiveRecord
      * 根据条件获取记录数量
      * @param array $condition 查询条件
      * @return int|string
+     * @throws \Exception
      */
     public function getCount($condition)
     {
@@ -383,6 +384,7 @@ class Base extends ActiveRecord
      * @param string|array $order 排序
      * @param string|array $with 关联查询
      * @return array ['totalNum' => int, 'totalPage' => int, 'moreData' => int, 'list' => array]
+     * @throws \Exception
      */
     public function getList($field, $where, $page, $pageSize, $order = '', $with = '')
     {
@@ -414,6 +416,7 @@ class Base extends ActiveRecord
      * @param string|array $order 排序
      * @param string|array $with 关联查询
      * @return array
+     * @throws \Exception
      */
     public function getAllList($field, $where, $order = '', $with = '')
     {
@@ -436,6 +439,7 @@ class Base extends ActiveRecord
      * @param string|array $order 排序
      * @param string|array $with 关联查询
      * @return array
+     * @throws \Exception
      */
     public function getLimitList($field, $where, $limit, $order = '', $with = '')
     {
@@ -490,6 +494,7 @@ class Base extends ActiveRecord
      * @param array $condition 查询条件
      * @param string $field 求和字段
      * @return mixed
+     * @throws \Exception
      */
     public function sum($condition, $field)
     {

+ 4 - 0
console/controllers/OrderController.php

@@ -2,6 +2,7 @@
 
 namespace console\controllers;
 
+use bizHd\hb\classes\HbClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\models\Order;
 use bizHd\purchase\classes\PurchaseClass;
@@ -113,6 +114,9 @@ class OrderController extends Controller
                     $order = OrderClass::getById($id, true);
                     //暂时只考虑花材库存的回滚
                     OrderClass::setExpire($order);
+                    if($order['hbId'] != 0){
+                        hbClass::hbBack($order['hbId']);
+                    }
                     $transaction->commit();
                     //noticeUtil::push("零售订单未付款,库存已回滚,单号:{$orderSn}");
                 } catch (\Exception $e) {

+ 1 - 1
scripts/db_struct.sh

@@ -56,7 +56,7 @@ echo "----------------------------------------"
 
 # 执行查询
 # -t 以表格形式输出
-mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" -t -e "DESCRIBE \`$TABLE_NAME\`;"
+mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" -t -e "SHOW FULL COLUMNS FROM \`$TABLE_NAME\`;"
 
 if [ $? -eq 0 ]; then
     echo "----------------------------------------"