| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace biz\goods\classes;
- use common\components\business;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use biz\base\classes\BaseClass;
- class CategoryClass extends BaseClass
- {
-
- public static $baseFile = '\biz\goods\models\Category';
-
- //可以使用的分类:花束 花盒 蝴蝶兰 花篮 植物 永生花 散花 充值卡 花艺课 花礼 瓶器
-
- //取出商家所有的分类 shish 2019.12.7
- public static function getCategoryIdList($merchantId)
- {
- $category = self::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0], null, '*', 'id');
- return empty($category) ? [] : array_keys($category);
- }
-
- //获取详情 shish 2019.12.8
- public static function getInfo($id)
- {
- $info = self::getById($id);
- $list = self::groupBaseInfo([$info]);
- return current($list);
- }
-
- //组合信息 shish 2019.12.8
- public static function groupBaseInfo($list)
- {
- foreach ($list as $key => $val) {
- $val = business::formatCategoryImg($val);
- $list[$key] = $val;
- }
- return $list;
- }
-
- //添加分类 shish 2019.12.8
- public static function addCategory($data)
- {
- $categoryName = $data['categoryName'];
- $merchantId = $data['merchantId'];
- $exists = self::getByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'categoryName' => $categoryName]);
- if (!empty($exists)) {
- util::fail('分类名称已经存在');
- }
- return self::add($data);
- }
-
- //分类启用与停用 shish 2019.12.8
- public static function changeStatus($categoryId, $status)
- {
- return self::updateById($categoryId, ['status' => $status]);
- }
-
- //开店初始化分类和商品 shish 2020.2.14
- public static function initCategoryGoods($merchantId)
- {
- $date = date("Y-m-d H:i:s");
- $list = [
- '花束' => [
- ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 188, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人1', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '1',],
- ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 288, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人2', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '2',],
- ],
- '花篮' => [
- ['shopImg' => '["\/uploads\/201906\/23\/jpg\/19062380217_12358.jpg","\/uploads\/201906\/23\/jpg\/19062339442_12358.jpg","\/uploads\/201906\/23\/jpg\/19062382963_12358.jpg"]', 'price' => 388, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人3', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '3',],
- ['shopImg' => '["\/uploads\/201906\/23\/jpg\/19062374848_12358.jpg","\/uploads\/201906\/23\/jpg\/19062372687_12358.jpg","\/uploads\/201906\/23\/jpg\/19062341158_12358.jpg"]', 'price' => 488, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人4', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '4',],
- ],
- '永生花' => [
- ['shopImg' => '["\/uploads\/201906\/23\/jpg\/19062359040_12358.jpg","\/uploads\/201906\/23\/jpg\/19062381985_12358.jpg"]', 'price' => 588, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人5', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '5',],
- ['shopImg' => '["\/uploads\/201906\/23\/jpg\/19062352536_12358.jpg","\/uploads\/201906\/23\/jpg\/19062331132_12358.jpg","\/uploads\/201906\/23\/jpg\/19062380371_12358.jpg"]', 'price' => 688, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人6', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '6',],
- ],
- '绿植' => []
- ];
- foreach ($list as $key => $goodsList) {
- $data = ['categoryName' => $key, 'merchantId' => $merchantId];
- $cat = self::add($data);
- if (!empty($goodsList)) {
- $categoryId = $cat['id'];
- foreach ($goodsList as $key => $val) {
- $goods = GoodsClass::add($val);
- $goodsId = $goods['id'];
- $goodsCategoryData = ['cId' => $categoryId, 'gId' => $goodsId, 'merchantId' => $merchantId];
- GoodsCategoryClass::add($goodsCategoryData);
- }
- }
- }
- }
-
- //删除分类 shish 2020.3.3
- public static function deleteCategory($id)
- {
- self::updateById($id, ['delStatus' => 1]);
- return true;
- }
-
- }
|