20], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城ID', 'goods_id' => '商品id', 'wallet_type' => '钱包类型[hi_bei:嗨贝,hi_value:嗨值]', 'is_enable' => '是否开启:0:否,1是', 'is_percent' => '是否百分比:0:否(固定金额),1是', 'give' => '赠送金额', 'deduct_type' => '商品抵扣类型[1:单件抵扣,2:多件抵扣]', 'deduct_money' => '商品抵扣金额', 'settlement_method' => '结算方式[;0:支付完成后;1:订单完成后]', 'status' => '状态[-1:删除;0:禁用;1启用]', 'source_id' => '来源id', 'source' => '来源标识; 主商城[Main], 插件对应插件标识', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * 保存设置 * @Author: lun * @DateTime: 2022/3/23 0023 14:26 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @param $goods_id * @param $list * @return bool */ public static function setGoodsSetting($mall_id, $goods_id, $list) { try { if (isset($list['enable_map'])) { $enable_map = $list['enable_map']; $goods_mode = HigoStoreGoodsMode::setGoodsSetting($mall_id, $goods_id, $enable_map); if ($goods_mode === false) { throw new Exception(HigoStoreGoodsMode::getStaticError()); } unset($list['enable_map']); } foreach ($list as $item) { $model = self::findOne([ 'mall_id' => $mall_id, 'goods_id' => $goods_id, 'wallet_type' => $item['wallet_type'], 'status' => StatusEnum::ENABLED, 'source' => $item['source'], 'source_id' => $item['source_id'], ]); if (empty($model)) { $model = new self(); $model->mall_id = $mall_id; $model->goods_id = $goods_id; $model->loadDefaultValues(); } if (!$model->load($item, '') || !$model->save()) throw new Exception($model->getErrorMessage()); } return true; } catch (\Exception $e) { self::setStaticError('商品嗨购设置失败:' . $e->getMessage()); return false; } } /** * 获取商品的优惠券设置 * @Author: lun * @DateTime: 2022/5/12 0012 14:49 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $params * @return bool|string[] */ public static function getGoodSetting($params) { // 后台页面组件展示 if ($params['type'] == 'show_component') { return [ 'component' => 'com-higo', 'path' => Yii::$app->basePath . '/../addons/HiGo/backend/views/goods', ]; } elseif ($params['type'] == 'show_store_component') { return [ 'component' => 'com-higo', 'path' => Yii::$app->basePath . '/../addons/HiGo/backend/views/goods/addons/store', ]; } elseif ($params['type'] == 'show_mch_component') { return [ 'component' => 'com-higo', 'path' => Yii::$app->basePath . '/../addons/HiGo/backend/views/goods/addons/mch', ]; } else { try { if (empty($params['setting'][AddonsEnum::ADDONS_NAME_HI_GO])) return true; $setting = $params['setting'][AddonsEnum::ADDONS_NAME_HI_GO]; // 数据保存 $res = self::setGoodsSetting($params['mall_id'], $params['goods_id'], $setting); if ($res === false) throw new Exception(self::getStaticError()); return true; } catch (Exception $e) { self::setStaticError($e->getMessage()); return false; } } } public function getGoodsModeCommssionType() { return [ [ 'name' => 'hi_bei', 'label' => '嗨贝' ], [ 'name' => 'hi_value', 'label' => '嗨值' ], ]; } /** * 获取商品 独立设置 * @param $goods_id * @param $wallet_type * @param string $source * @return array */ public static function getGoodsSetting($goods_id, $wallet_type, string $source = 'Main') { $setting = self::find()->where(['goods_id' => $goods_id, 'is_enable' => 1, 'status' => StatusEnum::ENABLED, 'wallet_type' => $wallet_type, 'source' => $source])->asArray()->one(); return $setting ?: []; } }