| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- <?php
- namespace addons\ShortVideo\common\models;
- use addons\ShortVideo\common\enums\AddonsShortVideoEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use common\models\mall\MallAddons;
- use common\models\order\Order;
- use common\models\order\OrderDetail;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_short_video}}".
- *
- * @property int $id
- * @property int $mall_id 商家id
- * @property int $user_id 用户id
- * @property string $title 标题
- * @property string $content 内容
- * @property string $video_url 视频路径
- * @property string $first_frame 首帧
- * @property int $video_wide 视频宽度
- * @property int $video_long 视频长度
- * @property string $duration_str 视频时长视频时长(时分秒字符串形式)
- * @property float $duration_seconds 视频时长(单位秒,浮点数形式)
- * @property int $related_type 关联类型1:关联商品 2:关联店铺 3:关联地址
- * @property int $related_goods_id 关联商品id
- * @property int $related_store_id 关联门店id
- * @property string $related_address 关联地址
- * @property string $related_detailed_address 关联详细地址
- * @property string $related_lon 关联经度
- * @property string $related_lat 关联维度
- * @property string $tag_id 标签id
- * @property int $open_integral_award 是否开启积分奖励 0:未开启 1:开启
- * @property int $open_money_award 是否开启现金奖励 0:未开启 1:开启
- * @property float $max_integral 积分最大值
- * @property float $surplus_integral 剩余的积分
- * @property float $spend_integral 花费积分
- * @property float $max_money 金额最大值
- * @property float $surplus_money 剩余金额
- * @property float $spend_money 花费金额
- * @property float $watch_integral_sum 观看奖励积分总和
- * @property float $watch_integral 观看奖励积分百分比
- * @property float $watch_integral_one 观看奖励积分一级百分比
- * @property float $watch_integral_two 观看奖励现金二级百分比
- * @property float $watch_money_sum 观看现金奖励总和
- * @property float $watch_money 观看奖励现金百分比
- * @property float $watch_money_one 观看奖励现金一级百分比
- * @property float $watch_money_two 观看奖励现金二级百分比
- * @property string $check_remark 审核备注
- * @property int $check_status 审核状态:0:未审核 1:审核通过 2:审核不通过
- * @property int $comment_num 评论量
- * @property int $like_num 点赞量
- * @property int $look_people_num 观看人数
- * @property int $look_complete_num 完整观看人数
- * @property int $look_num 浏览量
- * @property int $share_num 分享数量
- * @property int $share_click_num 分享点击数量
- * @property int $is_blacklist 是否拉黑0:否 1:是
- * @property int $is_top 是否置顶0:否 1:是
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $check_time 审核时间
- * @property int $top_time 置顶时间
- * @property int $blacklist_time 拉黑时间
- * @property int $created_at
- * @property int $updated_at
- */
- class ShortVideo extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_short_video}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id'], 'required'],
- [['mall_id', 'user_id', 'video_wide', 'video_long', 'related_type', 'related_goods_id', 'related_store_id', 'open_integral_award', 'open_money_award', 'check_status', 'comment_num', 'like_num', 'look_people_num', 'look_complete_num', 'look_num', 'share_num', 'share_click_num', 'is_blacklist', 'is_top', 'status', 'check_time', 'top_time', 'blacklist_time', 'created_at', 'updated_at'], 'integer'],
- [['max_integral', 'surplus_integral', 'spend_integral', 'max_money', 'surplus_money', 'spend_money', 'watch_integral_sum', 'watch_integral', 'watch_integral_one', 'watch_integral_two', 'watch_money_sum', 'watch_money', 'watch_money_one', 'watch_money_two', 'duration_seconds'], 'number'],
- [['title', 'content', 'video_url', 'first_frame', 'related_address', 'related_detailed_address', 'tag_id', 'check_remark'], 'string', 'max' => 255],
- [['related_lon', 'related_lat', 'duration_str'], 'string', 'max' => 20],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '会员ID',
- 'title' => '视频标题',
- 'content' => '描述内容',
- 'video_url' => '视频地址',
- 'first_frame' => '首帧',
- 'video_wide' => '视频宽度',
- 'video_long' => '视频长度',
- 'duration_str' => '视频时长视频时长(时分秒字符串形式)',
- 'duration_seconds' => '视频时长(单位秒,浮点数形式)',
- 'related_type' => '关联类型',
- 'related_goods_id' => '关联商品id',
- 'related_store_id' => '关联门店id',
- 'related_address' => '关联地址',
- 'related_detailed_address' => '关联详细地址',
- 'related_lon' => '关联经度',
- 'related_lat' => '关联维度',
- 'tag_id' => '标签id',
- 'open_integral_award' => '是否开启积分奖励',
- 'open_money_award' => '是否开启现金奖励',
- 'max_integral' => '积分最大值',
- 'surplus_integral' => '剩余的积分',
- 'spend_integral' => '花费积分',
- 'max_money' => '金额最大值',
- 'surplus_money' => '剩余金额',
- 'spend_money' => '花费金额',
- 'watch_integral_sum' => '观看奖励积分总和',
- 'watch_integral' => '观看奖励积分百分比',
- 'watch_integral_one' => '观看奖励积分一级百分比',
- 'watch_integral_two' => '观看奖励现金二级百分比',
- 'watch_money_sum' => '观看现金奖励总和',
- 'watch_money' => '观看奖励现金百分比',
- 'watch_money_one' => '观看奖励现金一级百分比',
- 'watch_money_two' => '观看奖励现金二级百分比',
- 'check_remark' => '审核备注',
- 'check_status' => '审核状态',
- 'comment_num' => '评论量',
- 'like_num' => '点赞量',
- 'look_people_num' => '观看人数',
- 'look_complete_num' => '完整观看人数',
- 'look_num' => '浏览量',
- 'share_num' => '分享数量',
- 'share_click_num' => '分享点击数量',
- 'is_blacklist' => '是否拉黑',
- 'is_top' => '是否置顶',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'check_time' => '审核时间',
- 'top_time' => '置顶时间',
- 'blacklist_time' => '拉黑时间',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @name:
- * @msg: 获取视频列表,包括正常视频列表、待审核列表、黑名单列表。此方法主要是后台使用
- * @param {int} $mall_id
- * @param {int} $list_type 列表类型,1:正常,2:待审核,3:黑名单
- * @param {array} $conditions 获取列表条件
- * @return array
- */
- public static function getList(int $mall_id, int $list_type, array $conditions = [])
- {
- if (1 == $list_type) {
- // 正常列表
- $is_blacklist = 0;
- $check_status = AddonsShortVideoEnum::VIDEO_AUDIT_STATUS1;
- } elseif (2 == $list_type) {
- // 审核中列表
- $is_blacklist = 0;
- $check_status = AddonsShortVideoEnum::VIDEO_AUDIT_STATUS0;
- } elseif (3 == $list_type) {
- $is_blacklist = 1;
- $check_status = AddonsShortVideoEnum::VIDEO_AUDIT_STATUS1;
- } else {
- throw new \Exception('参数错误:list_type');
- }
- $wheres[] = ['status' => StatusEnum::ENABLED, 'check_status' => $check_status, 'is_blacklist' => $is_blacklist, 'mall_id' => $mall_id];
- $users = [];
- if (!empty($conditions['user_nickname'])) {
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['status' => StatusEnum::ENABLED, 'mall_id' => $mall_id])
- ->andWhere(['like', 'nickname', $conditions['user_nickname']])
- ->asArray()
- ->indexBy('id')
- ->all();
- $wheres[] = ['user_id' => array_keys($users)];
- }
- if (!empty($conditions['related_type'])) $wheres[] = ['related_type' => $conditions['related_type']];
- if (!empty($conditions['video_title'])) $wheres[] = ['like', 'title', $conditions['video_title']];
- if (!empty($conditions['start_time'])) $wheres[] = ['>=', 'created_at', strtotime($conditions['start_time'] . ' 00:00:00')];
- if (!empty($conditions['end_time'])) $wheres[] = ['<=', 'created_at', strtotime($conditions['end_time'] . ' 23:59:59')];
- $params = [
- 'select' => 'id,user_id,title,first_frame,video_url,created_at,look_people_num,share_num,look_num,is_top,related_goods_id,related_type,spend_integral,spend_money,related_lon,related_lat,related_store_id,related_address,related_detailed_address,top_time',
- 'where' => $wheres,
- 'order' => 'is_top desc,created_at desc',
- 'page' => $conditions['page'],
- 'limit' => $conditions['limit'] ?? null,
- ];
- $video_list = ShortVideo::listPage($params);
- // $video_list = ShortVideo::getStaticError();
- // dd($video_list);
- if (empty($video_list['list'])) return $video_list;
- if (empty($users)) {
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['status' => StatusEnum::ENABLED, 'mall_id' => $mall_id, 'id' => array_column($video_list['list'], 'user_id')])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- $relate_good_ids = $relate_store_ids = [];
- foreach ($video_list['list'] as $list) {
- if (AddonsShortVideoEnum::VIDEO_RELATE_TYPE1 == $list['related_type']) $relate_good_ids[] = $list['related_goods_id'];
- if (AddonsShortVideoEnum::VIDEO_RELATE_TYPE2 == $list['related_type']) $relate_store_ids[] = $list['related_store_id'];
- }
- // 关联的商品信息
- if (empty($relate_good_ids)) {
- $goods = [];
- } else {
- $goods = Goods::find()
- ->select('id,goods_name,cover_pic,price')
- ->where(['id' => $relate_good_ids, 'mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'is_on_sale' => 1])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- // 关联的店铺的信息
- if (empty($relate_store_ids)) {
- $stores = [];
- } else {
- // TODO:关联的店铺的信息,系统还没有店铺应用,暂时不做
- $stores = [];
- }
- // 分享观看信息
- $video_ids = array_column($video_list['list'], 'id');
- $browse_rewards = ShortVideoBrowseAward::find()
- ->select('video_id,sum(award_integral) as reward_score,sum(award_money) as reward_money')
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'video_id' => $video_ids])
- ->groupBy('video_id')
- ->asArray()
- ->indexBy('video_id')
- ->all();
- // 转化金额
- $order_awards = ShortVideoOrderAward::find()
- ->select('video_id,order_id')
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'video_id' => $video_ids, 'is_award' => 1])
- ->asArray()
- ->all();
- $video_order_map = [];
- if (!empty($order_awards)) {
- foreach ($order_awards as $award) {
- $video_order_map[$award['video_id']][] = $award['order_id'];
- }
- foreach ($video_order_map as $video_id => $order_ids) {
- $orders = Order::find()
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $order_ids, 'pay_status' => OrderStatusEnum::PAY])
- ->asArray()
- ->all();
- $conversion[$video_id]['money'] = array_sum(array_column($orders, 'pay_money'));
- }
- } else {
- $conversion = [];
- }
- // 分红金额
- $dividends = ShortVideoOrderAward::find()
- ->select('sum(money) as money,video_id')
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'video_id' => $video_ids, 'is_award' => 1])
- ->groupBy('video_id')
- ->asArray()
- ->indexBy('video_id')
- ->all();
- // dd($users);
- // 遍历 list
- foreach ($video_list['list'] as &$video) {
- $video['nickname'] = ($users[$video['user_id']]['nickname'] ?? $users[$video['user_id']]['mobile']) ?? '';
- $video['mobile'] = $users[$video['user_id']]['mobile'] ?? '';
- $video['avatar_url'] = !empty($users[$video['user_id']]['avatar_url']) ? $users[$video['user_id']]['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- $video['goods_list'] = $goods[$video['related_goods_id']] ?? [];
- $video['store_name'] = $stores[$video['related_store_id']] ?? '';
- $video['conversion'] = floatval($conversion[$video['id']]['money'] ?? 0);
- $video['dividend'] = floatval($dividends[$video['id']]['money'] ?? 0);
- $browse_reward = $browse_rewards[$video['id']] ?? [];
- $video['reward_money'] = $browse_reward['reward_money'] ?? 0;
- $video['reward_score'] = $browse_reward['reward_score'] ?? 0;
- }
- return $video_list;
- }
- public static function setData(int $mall_id, array $data)
- {
- $transaction = \Yii::$app->db->beginTransaction();
- if (!empty($data['id'])) {
- $query = self::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]);
- if (!empty($data['user_id'])) $query->andWhere(['user_id' => $data['user_id']]);
- $model = $query->one();
- if (empty($model)) {
- $transaction->rollBack();
- self::$static_error = '视频不存在';
- return false;
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- $model->check_time = time();
- // 更新标签使用记录
- if (!empty($data['tag_id'])) {
- $tag_ids = explode(',', $data['tag_id']);
- // dd($tag_ids);
- $tags = ShortVideoTag::findAll(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $tag_ids]);
- if (!empty($tags)) {
- foreach ($tags as $tag) {
- $tag->usage_num += 1;
- $tag->save();
- unset($tag);
- }
- }
- }
- }
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- // dd($model);
- if (!$model->save()) {
- $transaction->rollBack();
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- $transaction->commit();
- return $model;
- }
- /**
- * @name:
- * @msg: 判断会员是否满足发布视频的条件
- * @param {int} $mall_id
- * @param {int} $user_id
- * @return {*}
- */
- public static function userCanPush(int $mall_id, int $user_id)
- {
- $configs = ShortVideoConfig::getConfig($mall_id);
- if (empty($configs)) {
- $rst = [
- 'is_can_push' => false,
- 'index' => [],
- 'errinfo' => [],
- ];
- return $rst;
- }
- $is_can_push = false;
- // dd($configs['release_rule']);
- if (1 == $configs['release_rule']) {
- // 消费次数
- if (1 == $configs['purchase_times_status']) {
- $order_counts = Order::find()
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $user_id, 'pay_status' => OrderStatusEnum::PAY])
- ->count();
- if ($order_counts >= $configs['purchase_times']) {
- $res_times = [
- 'consumed_times' => $order_counts,
- 'remainder_times' => 0,
- 'consume_times_res' => true,
- ];
- } else {
- $res_times = [
- 'consumed_times' => $order_counts,
- 'remainder_times' => $configs['purchase_times'] - $order_counts,
- 'consume_times_res' => false,
- ];
- }
- } else {
- $res_times = [
- 'consumed_times' => 0,
- 'remainder_times' => 0,
- 'consume_times_res' => true,
- ];
- }
- // 消费金额
- if (1 == $configs['purchase_cost_status']) {
- $order_amounts = Order::find()
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $user_id, 'pay_status' => OrderStatusEnum::PAY])
- ->sum('pay_money');
- if ($order_amounts >= $configs['purchase_cost']) {
- $res_amount = [
- 'consumed_amount' => $order_amounts,
- 'remainder_amount' => 0,
- 'consume_amount_res' => true,
- ];
- } else {
- $res_amount = [
- 'consumed_amount' => $order_amounts ?? 0,
- 'remainder_amount' => $configs['purchase_cost'] - $order_amounts ?? 0,
- 'consume_amount_res' => false,
- ];
- }
- } else {
- $res_amount = [
- 'consumed_amount' => 0,
- 'remainder_amount' => 0,
- 'consume_amount_res' => true,
- ];
- }
- // 消费商品
- if (1 == $configs['purchase_goods_status']) {
- $order_detail = OrderDetail::find()
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $user_id, 'goods_id' => $configs['purchase_goods_id']])
- ->andWhere(['>', 'order_status', OrderStatusEnum::PAY])
- ->one();
- $good = Goods::find()
- ->select('id,goods_name,cover_pic,price')
- ->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $configs['purchase_goods_id']])
- ->asArray()
- ->one();
- $res_good = [
- 'good' => $good,
- 'consume_good_res' => false,
- ];
- if (!empty($order_detail)) {
- $res_good['consume_good_res'] = true;
- }
- } else {
- $res_good = [
- 'good' => [],
- 'consume_good_res' => true,
- ];
- }
- } else {
- $res_times['consume_times_res'] = $res_amount['consume_amount_res'] = $res_good['consume_good_res'] = true;
- }
- if (true === $res_times['consume_times_res'] && true === $res_amount['consume_amount_res'] && true === $res_good['consume_good_res']) {
- $is_can_push = true;
- $rst = [
- 'is_can_push' => $is_can_push,
- 'index' => [],
- 'errinfo' => [],
- ];
- } else {
- $index = [];
- if (!$res_times['consume_times_res']) $index[] = 'times';
- if (!$res_amount['consume_amount_res']) $index[] = 'amount';
- if (!$res_good['consume_good_res']) $index[] = 'good';
- $rst = [
- 'is_can_push' => $is_can_push,
- 'index' => $index,
- 'errinfo' => ['times' => $res_times, 'amount' => $res_amount, 'good' => $res_good],
- ];
- }
- if (!$rst['is_can_push']) {
- if (empty($rst['index'])) {
- $res = [
- 'is_can_push' => $rst['is_can_push'],
- 'errmsg' => '您尚未满足达到视频的要求',
- ];
- } else {
- $errmsg = '您还需要再';
- foreach ($rst['index'] as $errindex) {
- if ('times' == $errindex) {
- $errmsg .= '消费 ' . $rst['errinfo'][$errindex]['remainder_times'] . ' 次 ';
- }
- if ('amount' == $errindex) {
- $errmsg .= '消费满 ' . $rst['errinfo'][$errindex]['remainder_amount'] . ' 元 ';
- }
- if ('good' == $errindex) {
- $errmsg .= '购买商品 【' . $rst['errinfo'][$errindex]['good']['goods_name'] . '】 ';
- }
- }
- $errmsg .= '后即可发布视频';
- $res = [
- 'is_can_push' => $rst['is_can_push'],
- 'errmsg' => $errmsg,
- 'good' => $rst['errinfo'][$errindex]['good'],
- ];
- }
- } else {
- $res = [
- 'is_can_push' => true,
- 'errmsg' => '您已达到发布视频的要求',
- ];
- }
- return $res;
- }
- /**
- * @name:
- * @msg: 会员浏览视频处理
- * @param {int} $mall_id
- * @param {array} $data video_id:视频id;user_id:当前会员id;share_log_id:该视频的分享记录id
- * @return {*}
- */
- public static function browse(int $mall_id, array $data)
- {
- $transaction = \Yii::$app->db->beginTransaction();
- $video = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['video_id'], 'check_status' => AddonsShortVideoEnum::VIDEO_AUDIT_STATUS1, 'is_blacklist' => 0]);
- if (empty($video)) {
- self::$static_error = '视频不存在';
- return false;
- }
- $video_params = [
- 'id' => $data['video_id'],
- 'look_num' => $video->look_num + 1,
- ];
- // 该会员之前是否看过改视频
- $video_browse = ShortVideoBrowse::findOne(['mall_id' => $mall_id, 'user_id' => $data['user_id'], 'video_id' => $data['video_id'], 'status' => StatusEnum::ENABLED]);
- if (empty($video_browse)) $video_params['look_people_num'] = $video->look_people_num + 1;
- // dd($video_params);
- $video_res = self::setData($mall_id, $video_params);
- if (false === $video_res) {
- $transaction->rollBack();
- return false;
- }
- $browse_data = [
- 'video_id' => $data['video_id'],
- 'user_id' => $data['user_id'],
- ];
- if (!empty($data['share_user_id'])) {
- $browse_data['is_share'] = 1;
- }
- $browse_res = ShortVideoBrowse::setData($mall_id, $browse_data);
- if (false === $browse_res) {
- $transaction->rollBack();
- self::$static_error = ShortVideoBrowse::getStaticError();
- return false;
- }
- $watch_data = [
- 'mall_id' => $mall_id,
- 'user_id' => $data['user_id'],
- 'video_id' => $data['video_id'],
- 'status' => StatusEnum::ENABLED,
- ];
- //记录观看记录
- $watch_res = ShortVideoUserWatch::setData($watch_data);
- if (false === $watch_res) {
- $transaction->rollBack();
- self::$static_error = ShortVideoUserWatch::getStaticError();
- return false;
- }
- $browse_num = ShortVideoBrowseNum::findOne(['mall_id' => $mall_id, 'user_id' => $data['user_id'], 'status' => StatusEnum::ENABLED]);
- $browse_times = $browse_num->look_num ?? 0;
- $browse_num_data = [
- 'user_id' => $data['user_id'],
- 'look_num' => $browse_times + 1,
- ];
- $browse_num_res = ShortVideoBrowseNum::setData($mall_id, $browse_num_data);
- if (false === $browse_num_res) {
- $transaction->rollBack();
- self::$static_error = ShortVideoBrowseNum::getStaticError();
- return false;
- }
- if (!empty($data['share_user_id'])) {
- $wheres = [
- 'mall_id' => $mall_id,
- 'status' => StatusEnum::ENABLED,
- 'user_id' => $data['share_user_id'],
- 'share_to_user_id' => 0,
- 'video_id' => $data['video_id'],
- ];
- $share_log = ShortVideoShare::find()
- ->where($wheres)
- ->orderBy('created_at desc')
- ->limit(1)
- ->one();
- if (!empty($share_log)) {
- $share_log->share_to_user_id = $data['user_id'];
- $sharelog_res = $share_log->save();
- if (false === $sharelog_res) {
- $transaction->rollBack();
- self::$static_error = $share_log->getErrors();
- return false;
- }
- }
- }
- $transaction->commit();
- return $browse_res;
- }
- /**
- * @desc:推广中心-调用
- * @Author: hua
- * @Date: 2021/11/12
- * @Time: 9:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params ['user_id' => 1, 'mall_id' => 5, 'addons_name' => 'Agent']
- * @return array
- */
- public static function getIncomeInfo(array $params)
- {
- $is_install = MallAddons::isInstall($params['mall_id'], $params['addons_name']);
- $data['total_commission'] = 0;
- $data['is_install'] = 0;
- $basic = \Yii::$app->services->setting->addons->get($params['mall_id'], $params['addons_name'], 'basic');
- $data['is_show_at_center'] = 1;
- if(isset($basic['is_show_at_center'])) $data['is_show_at_center'] = $basic['is_show_at_center'];
- if($is_install){
- $browse_reward = ShortVideoBrowseAward::find()
- ->where(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'status' => StatusEnum::ENABLED])
- ->sum('award_money');
- $order_reward = ShortVideoOrderAward::find()
- ->where(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'status' => StatusEnum::ENABLED, 'is_settlement' => 1, 'is_award' => 1])
- ->sum('award_money');
- $data['total_commission'] = $browse_reward * 1 + $order_reward * 1;
- $data['is_install'] = $is_install;
- }
- return $data;
- }
- }
|