CategoryClass.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace biz\goods\classes;
  3. use common\components\business;
  4. use common\components\stringUtil;
  5. use common\components\util;
  6. use Yii;
  7. use biz\base\classes\BaseClass;
  8. class CategoryClass extends BaseClass
  9. {
  10. public static $baseFile = '\biz\goods\models\Category';
  11. //可以使用的分类:花束 花盒 蝴蝶兰 花篮 植物 永生花 散花 充值卡 花艺课 花礼 瓶器
  12. //取出商家所有的分类 shish 2019.12.7
  13. public static function getCategoryIdList($merchantId)
  14. {
  15. $category = self::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0], null, '*', 'id');
  16. return empty($category) ? [] : array_keys($category);
  17. }
  18. //获取详情 shish 2019.12.8
  19. public static function getInfo($id)
  20. {
  21. $info = self::getById($id);
  22. $list = self::groupBaseInfo([$info]);
  23. return current($list);
  24. }
  25. //组合信息 shish 2019.12.8
  26. public static function groupBaseInfo($list)
  27. {
  28. foreach ($list as $key => $val) {
  29. $val = business::formatCategoryImg($val);
  30. $list[$key] = $val;
  31. }
  32. return $list;
  33. }
  34. //添加分类 shish 2019.12.8
  35. public static function addCategory($data)
  36. {
  37. $categoryName = $data['categoryName'];
  38. $merchantId = $data['merchantId'];
  39. $exists = self::getByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'categoryName' => $categoryName]);
  40. if (!empty($exists)) {
  41. util::fail('分类名称已经存在');
  42. }
  43. return self::add($data);
  44. }
  45. //分类启用与停用 shish 2019.12.8
  46. public static function changeStatus($categoryId, $status)
  47. {
  48. return self::updateById($categoryId, ['status' => $status]);
  49. }
  50. //开店初始化分类和商品 shish 2020.2.14
  51. public static function initCategoryGoods($merchantId)
  52. {
  53. $date = date("Y-m-d H:i:s");
  54. $list = [
  55. '花束' => [
  56. ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 188, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人1', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '1',],
  57. ['shopImg' => '["\/uploads\/201908\/01\/jpg\/19080166819_12358.jpg"]', 'price' => 288, 'content' => '暂无简介', 'merchantId' => $merchantId, 'createTime' => $date, 'updateTime' => $date, 'goodsName' => '天使美人2', 'itemNumber' => stringUtil::buildRandNo($merchantId) . '2',],
  58. ],
  59. '花篮' => [
  60. ['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',],
  61. ['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',],
  62. ],
  63. '永生花' => [
  64. ['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',],
  65. ['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',],
  66. ],
  67. '绿植' => []
  68. ];
  69. foreach ($list as $key => $goodsList) {
  70. $data = ['categoryName' => $key, 'merchantId' => $merchantId];
  71. $cat = self::add($data);
  72. if (!empty($goodsList)) {
  73. $categoryId = $cat['id'];
  74. foreach ($goodsList as $key => $val) {
  75. $goods = GoodsClass::add($val);
  76. $goodsId = $goods['id'];
  77. $goodsCategoryData = ['cId' => $categoryId, 'gId' => $goodsId, 'merchantId' => $merchantId];
  78. GoodsCategoryClass::add($goodsCategoryData);
  79. }
  80. }
  81. }
  82. }
  83. //删除分类 shish 2020.3.3
  84. public static function deleteCategory($id)
  85. {
  86. self::updateById($id, ['delStatus' => 1]);
  87. return true;
  88. }
  89. }