| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <?php
- namespace addons\ScoreExpansion\common\models;
- use addons\ScoreExpansion\common\enums\ScoreExpansionEnum;
- use common\models\order\OrderDetail;
- use common\models\order\Order;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_score_expansion}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string $title 活动标题
- * @property string $description 活动描述
- * @property string|null $cover 活动封面
- * @property float $award 总积分
- * @property float $virtual_award 虚拟积分
- * @property float $day_award 每日总积分
- * @property int $grab_user_num 已抢积分总人数
- * @property float $grab_integral 已抢积分总数额
- * @property float $surplus_integral 剩余积分总数额
- * @property int|null $data_at 数据更新时间
- * @property string $time_type 活动时间类型[1:每日积分,2:时间段积分]
- * @property string $start_time 活动开始时间
- * @property string $end_time 活动结束时间
- * @property int $integral_type 积分活动类型[1:冻结到激活积分,2:冻结积分,3:激活积分]
- * @property string|null $rule_values 规则条件的值集合 [
- * first_money_start:第一次抢积分数额最小值
- * first_money_end:第一次抢积分数额最大值
- * everyday_invitation:每日邀请人数
- * everyday_invitation_start:每日邀请人数可抢积分一次,单次数额在最小值
- * everyday_invitation_end:每日邀请人数可抢积分一次,单次数额在最大值
- * times:每日活动最多抢次数
- * ]
- * @property string $auth 参与权限
- * @property string|null $rule 规则说明
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property string|null $limit_user_level 会员限制
- * @property int $created_at
- * @property int $updated_at
- */
- class ScoreExpansion extends \common\models\base\BaseActiveRecord
- {
- const DAILY_INTEGRAL = 1;//每日积分
- const TIME_SLOT_INTEGRAL = 2;//时间段积分
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_score_expansion}}';
- }
- public static function briefTableName()
- {
- return 'addons_score_expansion';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'grab_user_num', 'data_at', 'integral_type', 'status', 'start_time', 'end_time'], 'integer'],
- [['award', 'day_award', 'grab_integral', 'surplus_integral','virtual_award'], 'number'],
- [['rule_values', 'rule','limit_user_level'], 'string'],
- [['title'], 'string', 'max' => 100],
- [['description', 'cover', 'auth'], 'string', 'max' => 255],
- [['time_type'], 'string', 'max' => 45],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'title' => '活动标题',
- 'description' => '活动描述',
- 'cover' => '活动封面',
- 'award' => '总积分',
- 'virtual_award' => '虚拟积分',
- 'day_award' => '每日积分池',
- 'grab_user_num' => '已抢积分总人数',
- 'grab_integral' => '已抢积分总金额',
- 'surplus_integral' => '剩余积分总数额',
- 'data_at' => '数据更新时间',
- 'time_type' => '活动时间类型[1:每日积分,2:时间段积分]',
- 'start_time' => '活动开始时间',
- 'end_time' => '活动结束时间',
- 'integral_type' => '红包活动类型[1:冻结到激活积分,2:增值冻结积分,3:增值激活积分]',
- 'rule_values' => '规则条件的值集合',
- 'auth' => '参与权限',
- 'rule' => '规则说明',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'limit_user_level' => '会员限制',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * @Author: ltm
- * @DateTime: 2022/3/18 0018 16:21
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public static function setData(array $params){
- try{
- if (!empty($params['id'])) {
- $model = self::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
- if($params['type'] == StatusEnum::ENABLED && $model->time_type == StatusEnum::ENABLED){ //每日积分活动重新启用的时候更新开始时间和结束时间
- $daytime = strtotime(date("Y-m-d"));
- $params['start_time'] = $daytime + strtotime(date("Y-m-d H:i:s",$model->start_time)) - strtotime(date("Y-m-d",$model->start_time));
- $params['end_time'] = $daytime + strtotime(date("Y-m-d H:i:s",$model->end_time)) - strtotime(date("Y-m-d",$model->end_time));
- }
- if (empty($model)) throw new Exception('记录不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- $model->mall_id = $params['mall_id'];
- // echo '<pre>';print_r($params);die;
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $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-score-expansion',
- 'path' => Yii::$app->basePath . '/../addons/ScoreExpansion/backend/views/goods',
- ];
- } else {
- try {
- if (empty($params['setting'][AddonsEnum::ADDONS_NAME_SCORE_EXPANSION])) return true;
- $setting = $params['setting'][AddonsEnum::ADDONS_NAME_SCORE_EXPANSION];
- // 数据保存
- $res = ScoreExpansionGoodsSetting::setGoodsSetting($params['mall_id'], $params['goods_id'], $setting);
- if ($res === false) throw new Exception(ScoreExpansionGoodsSetting::getStaticError());
- return true;
- } catch (Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
- /**
- * 分润明细类型
- * @return array[]
- */
- public function getGoodsModeCommssionType()
- {
- return [
- [
- 'name' => 'integral',
- 'label' => '激活积分'
- ],
- [
- 'name' => 'frozen_integral',
- 'label' => '冻结积分'
- ],
- ];
- }
- /**
- * 获取订单分润列表
- * @Author: lun
- * @DateTime: 2023/10/33 0012 14:49
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return bool|string[]
- */
- public static function getOrderListTab($params)
- {
- if (!isset($params['list']) || !is_array($params['list'])) return [];
- $order_id = $params['order_id'] ?? 0;
- $order_detail_id = $params['order_detail_id'] ?? null;
- $mall_id = $params['mall_id'] ?? 0;
- if ($order_id <= 0 && empty($order_detail_id)) return [];
- $wallet_type = $params['wallet_type'] ?? '';
- if (!in_array($wallet_type, [ScoreExpansionEnum::WALLET_INTEGRAL, ScoreExpansionEnum::WALLET_INTEGRAL_FROZEN])) {
- return [];
- }
- $order_detail_id_arr = $order_detail_id;
- if (!$order_detail_id_arr) {
- //查询order_detail
- $params = [];
- $params['where'] = [
- ['order_id' => $order_id],
- ['mall_id' => $mall_id],
- ];
- $order_detail_list = OrderDetail::lists($params);
- $order_detail_id_arr = array_column($order_detail_list, 'id');
- }
- $cond = [];
- $cond['where'] = [
- ['integral_wallet_type' => $wallet_type],
- //['source_table_id' => $order_id],
- // ['source_table' => '{{%order}}'],
- ['mall_id' => $mall_id],
- ['or',
- ['and',['source_table_id' => $order_id],['source_table' => Order::tableName()]],
- ['and',['source_table_id' => $order_detail_id_arr],['source_table' => 'order_detail']],
- ]
- ];
- // if($order_detail_id_arr){
- // $cond['where'][] = ['or',
- // ['or',['source_table_id' => $order_id],['source_table' => 'order']],
- // ['or',['source_table_id' => $order_detail_id_arr],['source_table' => 'order_detail']],
- // ];
- // }else{
- // $cond['where'][] = ['source_table_id' => $order_id];
- // $cond['where'][] = ['source_table' => Order::tableName()];
- // }
- $cond['with'] = ['user' => function ($query) {
- $query->select('id,nickname,avatar_url');
- }];
- $list = ScoreExpansionWalletLog::lists($cond);
- $wallet_log_status = ScoreExpansionEnum::getRedpackText();
- $from_type_map = ScoreExpansionEnum::getFromType();
- $addons_name_map = AddonsEnum::getAddonsNameMap();
- foreach ($list as &$value) {
- // $value['is_frozen'] = $wallet_log_status[$value['integral_wallet_type']] ?? '';//状态
- $value['is_frozen'] = '已结算';//状态
- $value['capital_type_text'] = $from_type_map[$value['from_type']] ?? '';//类型
- $value['from_type_text'] = $addons_name_map[ScoreExpansionEnum::ADDONS_NAME] ?? '';
- $value['nickname'] = $value['user']['nickname'];
- $value['avatar_url'] = $value['user']['avatar_url'];
- unset($value['user']['avatar_url'], $value['user']['nickname']);
- }
- return $list;
- }
- }
|