'ID', 'mall_id' => '商城id', 'user_id' => '用户id', 'note_id' => '笔记id', 'has_gift' => '是否奖励', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function setData($id, $user_id) { $state = false; $num = 0; $content = ''; $transaction = \Yii::$app->db->beginTransaction(); try { $model = new self(); $ins_data['mall_id'] = 1; $ins_data['user_id'] = $user_id; $ins_data['note_id'] = $id; $model->load($ins_data, ''); $model->save(); $note = AddonsOperatingNoteContent::getOne([['id' => $id]], false, [], false); if ($note['share_reward'] == 1) { $record_count = self::count(['where' => [['=', 'user_id', $user_id], ['=', 'note_id', $id], ['=', 'has_gift', 1]]]); if ($record_count < $note->share_reward_max_time) { if (in_array($note->share_reward_type, [0, 1])) { if ($note->share_reward_type == 0) { $content = '积分'; $wallet_type = UserWalletService::WALLET_TYPE_SCORE; } if ($note->share_reward_type == 1) { $content = '余额'; $wallet_type = UserWalletService::WALLET_TYPE_BALANCE; } $handle_wallet = [ 'message_id' => 0, 'mall_id' => $note->mall_id, 'user_id' => $user_id, 'wallet_type' => $wallet_type, 'money' => $note->share_reward_content, 'desc' => '分享文章奖励', 'source_table' => AssetsType::OPERATING_NOTE, 'source_table_id' => $model->id, 'from_type' => UserWalletEnum::REWARD, 'capital_type' => UserWalletEnum::OPERATING_NOTE_SHARE, ]; $reward_state = UserWalletService::handle(0, $handle_wallet); } else { // 红包 $reward_state = RedpackWallet::setData([ 'mall_id' => $note->mall_id, 'user_id' => $user_id, 'is_frozen' => false, 'money' => $note->share_reward_content, 'source_table' => static::tableName(), 'source_table_id' => $note->id, 'from_type' => RedpackEnum::FROM_RECEIVE, 'desc' => "运营笔记ID: {$id}分享奖励", ]); } if ($reward_state) { $state = true; $num = $note->share_reward_content; $model->has_gift = 1; $model->save(); $reward = new AddonsOperatingNoteRewardRecord(); $reward->mall_id = $note->mall_id; $reward->user_id = $user_id; $reward->note_content_id = $id; $reward->note_cate_id = $note->cate_id; $reward->note_type = $note->note_type; $reward->reward_type = $note->share_reward_type; $reward->reward_source = NoteEnum::STATUS_TWO; $reward->reward_content = $note->share_reward_content; $reward->save(); } } } $note->share_num++; $note->save(); $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); var_dump($e->getMessage()); throw new Exception($e->getMessage()); } return ['state' => $state, 'content' => $content, 'num' => $num]; } }