255], [['duration_str'], 'string', 'max' => 20], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'store_id' => 'Store ID', 'user_id' => 'User ID', 'title' => 'Title', 'content' => 'Content', 'goods_id' => 'Goods ID', 'reward_amount' => 'Reward Amount', 'viewing_times' => 'Viewing Times', 'video_url' => 'Video Url', 'first_frame' => 'First Frame', 'video_wide' => 'Video Wide', 'video_long' => 'Video Long', 'duration_str' => 'Duration Str', 'duration_seconds' => 'Duration Seconds', 'is_on_sale' => 'is_on_sale', 'check_remark' => 'Check Remark', 'check_status' => 'Check Status', 'check_time' => 'Check Time', 'look_people_num' => 'Look People Num', 'look_complete_num' => 'Look Complete Num', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function setData($params) { $t = Yii::$app->db->beginTransaction(); try{ $model = new self(); $model->loadDefaultValues(); $store = Store::findOne(['user_id'=>$params['user_id'],'status'=>StatusEnum::ENABLED]); if(empty($store)) throw new Exception('您没有权限发布视频'); $params['store_id'] = $store['id']; if (!$model->load($params, '') || !$model->save()) throw new \PHPUnit\Util\Exception($model->getErrorMessage()); $params['video_id'] = $model['id']; $params['order_no'] = StringHelper::generateOrderNo('v'); $params['pay_money'] = bcmul($params['reward_amount'],$params['viewing_times'],2); $video_order = StoreVideoOrder::setData($params); if (!$video_order) throw new Exception(StoreVideoOrder::getStaticError()); $order_trade_info[] = [ 'order_no' =>$params['order_no'] , 'amount' => $params['pay_money'], 'title' => $params['title'], 'notify_class' => 'addons\Store\common\logic\notify\VideoOrderNotify', 'order_type' => 'video_order', ]; $res = \Yii::$app->services->pay->createTrade($params['mall_id'], $params['user_id'], $order_trade_info); if (!$res) throw new \Exception('生成支付流水失败'); $t->commit(); $res['order_ids'] = $video_order['id']; $arr['transaction'] = $res; $arr['pay_success_page'] = Yii::$app->services->setting->mall->get($params['mall_id'], 'order.pay_after_link'); // 支付成功后跳转的地址 $payment_expire_time = Yii::$app->services->setting->mall->get($params['mall_id'], 'order.payment_expire_time'); $arr['surplus_second'] = 30 * 60; //剩余秒数 if ($payment_expire_time) { $arr['surplus_second'] = intval($payment_expire_time) * 60; //剩余秒数 } return $arr; }catch(\Exception $e){ $t->rollBack(); self::$static_error = $e->getMessage(); return false; } } //发放观看视频广告奖励余额 public static function grantReward($params){ $video = StoreVideo::findOne(['id'=>$params['video_id']]); if(empty($video)) return true; $lock_key = RedisKeyEnum::suffix(RedisKeyEnum::LOCK_STORE_VIDEO , $video['id']); $identification = uniqid(); try { if (!LockHelper::lock($lock_key, $identification, 30, 60)) throw new Exception('当前访问人数过多'); if($video['look_complete_num']>=$video['viewing_times']){ $video->is_on_sale = 0; }else{ $rate = 0;//广告扣除比例 if(MallAddons::isInstall($video['mall_id'],'Seed')){ $ad_percent = Yii::$app->services->setting->addons->get($video['mall_id'], 'Seed', 'basic.ad_percent'); if(!empty($ad_percent)) $rate = $ad_percent; } $rate_money = bcdiv($video['reward_amount']*$rate,100,2) ; $money = bcsub($video['reward_amount'],$rate_money,2); if($money>0){ CapitalLog::$capitalType = UserWalletService::WALLET_TYPE_BALANCE; $condition = [ 'mall_id' => $params['mall_id'], 'user_id'=>$params['user_id'], 'source_table'=>StoreVideo::tableName(), 'source_table_id'=>$params['video_id'], 'from_type' => UserWalletEnum::REWARD, 'capital_type' => UserWalletEnum::VIDEO_AD_REWARD ]; $res = CapitalLog::findOne($condition); if($res) throw new Exception('已发放过奖励'); $insert_wallet [] = [ 'mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'is_frozen' => false, 'wallet_type' =>UserWalletService::WALLET_TYPE_BALANCE, 'money' => $money, 'desc' => '观看视频广告获得奖励余额', 'source_table' => StoreVideo::tableName(), 'source_table_id' => $params['video_id'], 'from_type' => UserWalletEnum::REWARD, 'capital_type' => UserWalletEnum::VIDEO_AD_REWARD, ]; $res = UserWalletService::batchHandleByQueue($insert_wallet); if($res==false) throw new Exception('投入资金队列返回错误'); } } if($video['look_complete_num']+1>=$video['viewing_times']){ $video->is_on_sale = 0; } $video->look_complete_num++; $video->save(); LockHelper::ulock($lock_key,$identification); return true; }catch (\Exception $e){ LockHelper::ulock($lock_key,$identification); return false; } } public static function browse($params){ $video = StoreVideo::findOne(['id'=>$params['video_id']]); if(empty($video)) return true; $video->look_people_num++; return $video->save(); } }