| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace addons\Store\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "qimall_addons_store_goods_extra".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $store_id 门店id
- * @property int $goods_id 商品ID
- * @property float $full_reduce_money 单品满额减免金额
- * @property float $full_reduce_price_limit 单品满额金额阈值
- * @property string|null $score_give_setting 积分赠送设置
- * @property string|null $score_deduct_setting 积分抵扣设置
- * @property string|null $currency_deduct_setting 货币营销设置
- * @property int $is_member_price 是否参与会员价 [1是 0 否]
- * @property string|null $member_price_setting 会员价格设置
- * @property string|null $member_buy_limit_setting 会员限购设置
- * @property int is_repurchase 是否开启复购价[0=否, 1=是]
- * @property string|null repurchase_setting 复购价设置
- * @property int $status 状态[1正常 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class StoreGoodsExtra extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_goods_extra}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'goods_id', 'is_member_price', 'status', 'created_at', 'updated_at', 'is_repurchase','is_alone_settle', 'is_hidden_member_price', 'member_price_switch', 'is_show_price'], 'integer'],
- [['full_reduce_money', 'full_reduce_price_limit','alone_settle_price'], 'number'],
- [['score_give_setting', 'score_deduct_setting', 'currency_deduct_setting', 'member_price_setting', 'member_buy_limit_setting', 'repurchase_setting', 'service_fee_setting'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'store_id' => '门店id',
- 'goods_id' => '商品ID',
- 'full_reduce_money' => '单品满额减免金额',
- 'full_reduce_price_limit' => '单品满额金额阈值',
- 'score_give_setting' => '积分赠送设置',
- 'score_deduct_setting' => '积分抵扣设置',
- 'currency_deduct_setting' => '货币营销设置',
- 'is_member_price' => '是否参与会员价 [1是 0 否]',
- 'member_price_setting' => '会员价格设置',
- 'member_buy_limit_setting' => '会员限购设置',
- 'is_repurchase' => '是否开启复购价[0=否, 1=是]',
- 'repurchase_setting' => '复购价设置',
- 'status' => '状态[1正常 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- /**
- * 保存数据
- * @param $params
- * @return bool
- */
- public static function setData($goods_id,$params)
- {
- try{
- // 判断参数中是否存在数组,存在则转为json字符串
- foreach ($params as $key => &$item) {
- $item = is_array($item) ? json_encode($item,JSON_UNESCAPED_UNICODE) : $item;
- }
- // 根据商品id获取商品信息
- $model = self::findOne(['goods_id' => $goods_id,'status'=>StatusEnum::ENABLED]);
- if (empty($model)) {
- // 初始化商品额外参数
- $model = new self();
- $model->loadDefaultValues();
- }
- $model->goods_id = $goods_id;
- if(!$model->load($params,'') || !$model->save(false)){
- throw new \Exception($model->getErrorMessage());
- }
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 购买条件验证
- * @Author bing
- * @DateTime 2021-09-27 14:20:53
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param [type] $user
- * @param [type] $limit_setting
- * @return bool
- */
- public static function buyLimitValidate($user,&$limit_setting){
- try{
- if(!empty($limit_setting)){
- if(!in_array($user->level,$limit_setting['member_level'])){
- throw new \Exception('你的等级不支持购买该商品');
- }
- foreach($limit_setting as $key => $val){
- if($val == 0) continue;
- }
- }
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function updateServiceFeeSetting($params)
- {
- $max_platform_ratio = $params['max_platform_ratio'];
- $min_platform_ratio = $params['min_platform_ratio'];
- $query = self::find()
- ->where([
- 'mall_id' => $params['mall_id'],
- 'status' => StatusEnum::ENABLED,
- ])
- ->select(['id', 'service_fee_setting']);
- foreach ($query->each() as $row) {
- $setting = Json::decode($row['service_fee_setting']);
- if (isset($setting['service_fee_ratio']) && $setting['is_alone'] == 1) {
- $ratio = $setting['service_fee_ratio'];
- if ($ratio < $min_platform_ratio || $ratio > $max_platform_ratio) {
- $setting['service_fee_ratio'] = $max_platform_ratio;
- \Yii::$app->db->createCommand()
- ->update(self::tableName(), [
- 'service_fee_setting' => Json::encode($setting)
- ], ['id' => $row['id']])
- ->execute();
- }
- }
- }
- }
- }
|