| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace biz\goods\classes;
- use common\components\business;
- 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], 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, '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'],
- ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 288, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人2']
- ],
- '花篮' => [
- ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 388, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人3'],
- ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 488, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人4']
- ],
- '永生花' => [
- ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 588, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人5'],
- ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 688, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人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);
- }
- }
- }
- }
-
- }
|