| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace biz\goods\classes;
- use common\components\business;
- use Yii;
- use biz\base\classes\BaseClass;
- class GoodsStyleClass extends BaseClass
- {
-
- public static $baseFile = '\biz\goods\models\GoodsStyle';
-
-
- //组装下款式需要用的信息 shish 2019.12.4
- public static function groupStyleInfo($list)
- {
- foreach ($list as $key => $val) {
- //大中小图片转化
- $val = business::formatGoodsStyleImg($val);
- $list[$key] = $val;
- }
- return $list;
- }
-
- //取商品的款式和价格
- public static function getStyleList($id)
- {
- $list = self::getAllByCondition(['goodsId' => $id], 'inTurn DESC', '*', 'id');
- if (empty($list)) {
- return $list;
- }
- $new = self::groupStyleInfo($list);
- return $new;
- }
-
- /*
- 更新商品的款式 shish 2020.2.27
- 输入的数据格式 [
- ['styleName' => '红色1', 'price' => 0.1, 'picture' => '', 'action' => 'add', 'id' => 0],
- ['styleName' => '蓝色', 'price' => 0.1, 'picture' => '', 'action' => 'update', 'id' => 1],
- ['styleName' => '黑色2', 'price' => 0.1, 'picture' => '', 'action' => 'delete', 'id' => 2]
- ];
- */
- public static function updateGoodsStyle($goodsStyleList, $goodsId)
- {
- $add = [];
- $update = [];
- $delete = [];
- foreach ($goodsStyleList as $goodsStyle) {
- $action = $goodsStyle['action'];
- $id = $goodsStyle['id'];
- switch ($action) {
- case 'add':
- unset($goodsStyle['id']);
- $add[] = $goodsStyle;
- break;
- case 'update':
- $update[] = $goodsStyle;
- break;
- case 'delete':
- $delete[] = $id;
- break;
- default:
- $add[] = $goodsStyle;
- }
- }
- if (!empty($add)) {
- $addStyle = [];
- foreach ($add as $style) {
- $addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $goodsId, 'picture' => $style['picture'], 'price' => $style['price']];
- }
- GoodsStyleClass::batchAdd($addStyle);
- }
- if (!empty($delete)) {
- GoodsStyleClass::deleteByIds($delete);
- }
- if (!empty($update)) {
- foreach ($update as $up) {
- $currentId = $up['id'];
- unset($up['id']);
- self::updateById($currentId, $up);
- }
- }
- }
- }
|