| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- namespace addons\HiGo\common\models;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_higo_goods_setting}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $goods_id 商品id
- * @property int $source_id 来源id
- * @property string $source 来源标识; 主商城[Main], 插件对应插件标识
- * @property int|null $wallet_type 钱包类型[hi_bei:嗨贝,hi_value:嗨值]
- * @property int $is_enable 是否开启:0:否,1是
- * @property int $is_percent 是否百分比:0:否(固定金额),1是
- * @property float $give 赠送红包金额
- * @property int $deduct_type 商品抵扣类型[1:单件抵扣,2:多件抵扣]
- * @property int $settlement_method 结算方式[;0:支付完成后;1:订单完成后]
- * @property float $deduct_money 商品抵扣金额
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class HigoGoodsSetting extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_higo_goods_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'goods_id', 'is_enable', 'is_percent', 'deduct_type', 'status', 'created_at', 'updated_at', 'settlement_method', 'source_id'], 'integer'],
- [['give', 'deduct_money'], 'number'],
- [['wallet_type', 'source'], 'string', 'max' => 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 ?: [];
- }
- }
|