diff --git a/app/api/logic/LocalStoreGoodsLogic.php b/app/api/logic/LocalStoreGoodsLogic.php index 6b0628b4..9367d1a4 100644 --- a/app/api/logic/LocalStoreGoodsLogic.php +++ b/app/api/logic/LocalStoreGoodsLogic.php @@ -5,22 +5,22 @@ namespace app\api\logic; use app\common\basics\Logic; use app\common\model\localstore\LocalStoreGoods; use app\common\model\localstore\LocalStoreGoodsPic; -use app\common\enum\LocalStoreFileEnum; +use app\common\enum\LocalStoreGoodsEnum; use think\facade\Config; class LocalStoreGoodsLogic extends Logic { - private static $STATUS = [ - 'stay' => 0, // 默认 - 'shelves' => 1, // 已上架 - 'status_sold_out' => 2 // 已下架 - ]; - - private static $AUDIT_STATUS = [ - 'audit_status_stay' => 0, // 待审核 - 'audit_status_ok' => 1, // 审核通过 - 'audit_status_refuse' => 2 // 审核失败 - ]; +// private static $STATUS = [ +// 'stay' => 0, // 默认 +// 'shelves' => 1, // 已上架 +// 'status_sold_out' => 2 // 已下架 +// ]; +// +// private static $AUDIT_STATUS = [ +// 'audit_status_stay' => 0, // 待审核 +// 'audit_status_ok' => 1, // 审核通过 +// 'audit_status_refuse' => 2 // 审核失败 +// ]; // 获取商品列表 public static function lists($get) @@ -28,17 +28,17 @@ class LocalStoreGoodsLogic extends Logic // 1 已上架 2 已下架 if ($get['type'] == 1 || $get['type'] == 2) { $where[] = ['state', '=', $get['type']]; - $where[] = ['audit_status', '=', self::$AUDIT_STATUS['audit_status_ok']]; // 审核成功 + $where[] = ['audit_status', '=', LocalStoreGoodsEnum::AUDIT_STATUS_OK]; // 审核成功 } // 待审核 if ($get['type'] == 3) { - $where[] = ['audit_status', '=', self::$AUDIT_STATUS['audit_status_stay']]; + $where[] = ['audit_status', '=', LocalStoreGoodsEnum::AUDIT_STATUS_STAY]; } // 审核失败 if ($get['type'] == 4) { - $where[] = ['audit_status', '=', self::$AUDIT_STATUS['audit_status_refuse']]; + $where[] = ['audit_status', '=', LocalStoreGoodsEnum::AUDIT_STATUS_REFUSE]; } $m_where[] = ['lstore_id', '=', $get['lstore_id']]; @@ -62,10 +62,10 @@ class LocalStoreGoodsLogic extends Logic } // 统计待审核的商品数量 - $stay_goods_count = LocalStoreGoods::where($m_where)->where(['audit_status' => self::$AUDIT_STATUS['audit_status_stay']])->count(); + $stay_goods_count = LocalStoreGoods::where($m_where)->where(['audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_STAY])->count(); // 统计审核失败的商品数量 - $fail_goods_count = LocalStoreGoods::where($m_where)->where(['audit_status' => self::$AUDIT_STATUS['audit_status_refuse']])->count(); + $fail_goods_count = LocalStoreGoods::where($m_where)->where(['audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_REFUSE])->count(); $result = [ 'stay_goods_count' => $stay_goods_count, @@ -94,7 +94,7 @@ class LocalStoreGoodsLogic extends Logic 'price' => $form['price'], 'desc' => $form['desc'] ?? '', 'details' => $form['details'] ?? '', - 'state' => self::$STATUS['shelves'], + 'state' => LocalStoreGoodsEnum::SHELVES, 'create_time' => time(), ]); } else if ($form['type'] === 'edit') { @@ -103,7 +103,7 @@ class LocalStoreGoodsLogic extends Logic 'price' => $form['price'], 'desc' => $form['desc'] ?? '', 'details' => $form['details'] ?? '', - 'audit_status' => self::$AUDIT_STATUS['audit_status_stay'], + 'audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_STAY, 'update_time' => time(), ]); @@ -185,7 +185,7 @@ class LocalStoreGoodsLogic extends Logic 'id' => $get['id'], 'lstore_id' => $get['lstore_id'], 'delete_time' => 0, - 'audit_status' => self::$AUDIT_STATUS['audit_status_ok'], + 'audit_status' => LocalStoreGoodsEnum::AUDIT_STATUS_OK, ])->find()->toArray(); if ($data) { @@ -201,12 +201,16 @@ class LocalStoreGoodsLogic extends Logic // 设置状态 public static function setState($form, $user_id) { - if (isset(self::$STATUS[$form['type']])) { - $state = self::$STATUS[$form['type']]; + if ($form['type'] == LocalStoreGoodsEnum::SHELVES || $form['type'] == LocalStoreGoodsEnum::STATUS_SOLD_OUT) { $result = LocalStoreGoods::where(['id' => $form['id'], 'user_id' => $user_id, 'lstore_id' => $form['lstore_id']])->update([ - 'state' => $state, + 'state' => $form['type'], ]); - return $result; + + if ($result) { + return $result; + } + + return false; } return false; } diff --git a/app/common/enum/LocalStoreGoodsEnum.php b/app/common/enum/LocalStoreGoodsEnum.php new file mode 100755 index 00000000..3a04632e --- /dev/null +++ b/app/common/enum/LocalStoreGoodsEnum.php @@ -0,0 +1,20 @@ +