255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => '自增id', 'mall_id' => '商城id', 'name' => '电子券名称', 'amount' => '发行数量;单张券为张', 'receive_times' => '最多领取次数', 'unlimit_receive_times' => '领取次数不限制', 'pieces_type' => '1单张2多张;', 'pieces_amount' => '多张数量;单位张', 'receive_codition' => '领取条件;1全体会员;2指定会员等级;', 'receive_member_level' => '指定会员等级;默认为null', 'receive_begin_time' => '领取开始时间', 'receive_end_time' => '领取结束时间', 'use_begin_time' => '使用开始时间', 'use_end_time' => '使用结束时间', 'price' => '激活金额', 'reward_money' => '奖励金额', 'use_way' => '适用范围;1扫描核销', 'is_can_receive' => '是否可以被领取', 'is_show_in_center' => '是否出现在领取中心', 'rules' => '电子券规则', 'pic' => '缩略图', 'no_receive_amount' => '未领取数量', 'receive_amount' => '领取数量;单张券为张;', 'used_amount' => '兑换数量;单位张或多张', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'sort' => '排序;由大到小', 'is_give' => '是否赠送电子券', 'is_proper' => '是否专有券', 'status' => '状态[-1:删除;0:禁用;1启用]', 'give_score' => '赠送积分', 'give_price' => '赠送佣金', 'give_store_price' => '核销门店奖励', 'share_expiry' => '分享有效期,单位小时', 'give_quantity' => '赠送数量', ]; } /** * @Author: ltm * @DateTime: 2022/6/27 0012 17:30 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $data * @return string */ public static function getGoodSetting($params) { // 后台页面组件展示 if ($params['type'] == 'show_component') { return [ 'component' => 'com-electron-coupon', 'path' => Yii::$app->basePath . '/../addons/ElectronCoupon/backend/views/goods', ]; } else { try { if (empty($params['setting'][ElectronCouponEnums::ADDONS_NAME])) return true; $setting = $params['setting'][ElectronCouponEnums::ADDONS_NAME]; // 数据保存 //var_dump($setting['electron_selection']);die; //统一设置无效 ElectronCouponGoods::setCanceGoods($params); if ($setting['electron_selection']) { $data['is_open'] = $setting['is_open']; $data['send_type'] = $setting['send_type']; foreach ($setting['electron_selection'] as $k => $v) { $data['num'] = $v['num']; $data['status'] = StatusEnum::ENABLED; $data['e_coupon_id'] = $v['coupon_id']; $res = ElectronCouponGoods::setGoodsData($params['mall_id'], $params['goods_id'], $data); if ($res === false) throw new Exception(ElectronCouponGoods::getStaticError()); } } return true; } catch (Exception $e) { self::setStaticError($e->getMessage()); return false; } } } /** * @Author: ltm * @DateTime: 2022/6/27 0012 12:45 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $data * @return string */ public static function isInstall(array $params) { //插件判断 是否显示卡密信息 $addons = MallAddons::isInstall($params['mall_id'], ElectronCouponEnums::ADDONS_NAME); $data = $params['order']; if ($addons) { $data[ElectronCouponEnums::ADDONS_NAME]['is_show_addons'] = 1; } else { $data[ElectronCouponEnums::ADDONS_NAME]['is_show_addons'] = 0; } return $data; } /** * 数据设置 * @param array $params * int receive_amount 未激活数量,传入数量进行加减计算 * int used_amount 已使用数量,传入数量进行加减计算 * @return ElectronCoupon|bool|null */ public static function setData(array $params) { try { $params['receive_amount'] = $params['receive_amount'] ?? 0; $params['used_amount'] = $params['used_amount'] ?? 0; $params['status'] = $params['status'] ?? 1; $params['give_quantity'] = $params['give_quantity'] ?? 0; if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID'); $mall_id = $params['mall_id']; if (isset($params['id']) && !empty($params['id'])) { $model = self::findOne(['id' => $params['id'], 'mall_id' => $mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new Exception('电子券不存在或已删除'); $bcmath = ['receive_amount', 'used_amount']; foreach ($bcmath as $field) { if (isset($params[$field])) { $model[$field] = $model[$field] + $params[$field]; unset($params[$field]); } } } else { $model = new self(); $model->loadDefaultValues(); $model->mall_id = $mall_id; } if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage()); return $model; } catch (Exception $e) { self::setStaticError($e->getMessage()); return false; } } /** * 修改是否显示在首页 * * @param $mall_id * @param $id * @param $is_show_in_center * @return ElectronCoupon|false */ public static function changeIsShowInCenter($mall_id, $id, $is_show_in_center) { try { $model = self::findOne(['id' => $id, 'mall_id' => $mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new Exception('电子券不存在或已删除'); $model->is_show_in_center = $is_show_in_center; if (!$model->save()) throw new Exception($model->getErrorMessage()); return $model; } catch (Exception $e) { self::setStaticError($e->getMessage()); return false; } } /** * 修改状态 * * @param $mall_id * @param $id * @param $status * @return ElectronCoupon|false */ public static function changeStatus($mall_id, $id, $status) { try { $model = self::findOne(['id' => $id, 'mall_id' => $mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new Exception('电子券不存在或已删除'); $model->status = $status; if (!$model->save()) throw new Exception($model->getErrorMessage()); return $model; } catch (Exception $e) { self::setStaticError($e->getMessage()); return false; } } }