CategoryClass.php 3.5 KB

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