| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- namespace addons\OperationCenter\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_operation_center_commission_log}}".
- *
- * @property int $id
- * @property int $mall_id Mall ID
- * @property int $user_id 用户ID
- * @property int $from_user_id 来源会员ID
- * @property int $level 运营中心等级
- * @property string|null $goods_name 商品名称
- * @property float $goods_price 商品售价
- * @property string|null $order_no 订单编号
- * @property int $commission_level 推荐佣金等级(直推,间推)
- * @property int $order_id 订单ID
- * @property int $order_detail_id 订单详情ID
- * @property int $setting_log_id 设置logID
- * @property float $commission_amount 佣金数量
- * @property int $status 0 待结算 1 已结算
- * @property int|null $deleted_at
- * @property int|null $updated_at
- * @property int|null $created_at
- */
- class CommissionLog extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_operation_center_commission_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'from_user_id', 'level', 'commission_level', 'order_id', 'order_detail_id', 'setting_log_id'], 'required'],
- [['mall_id', 'user_id', 'from_user_id', 'level', 'commission_level', 'order_id', 'order_detail_id', 'setting_log_id', 'status', 'deleted_at', 'updated_at', 'created_at'], 'integer'],
- [['goods_price', 'commission_amount'], 'number'],
- [['goods_name'], 'string', 'max' => 64],
- [['order_no'], 'string', 'max' => 32],
- ];
- }
- /**
- * 关联用户
- * @Author: lun
- * @DateTime: 2023/8/18 0018 15:45
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getFromUser()
- {
- return $this->hasOne(MallUser::class, ['id' => 'from_user_id'])->select('id, mobile, nickname, avatar_url');
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getUser()
- {
- return $this->hasOne(MallUser::class, ['id' => 'user_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getLevelInfo()
- {
- return $this->hasOne(Level::class, ['level' => 'level', 'mall_id' => 'mall_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getOrder()
- {
- return $this->hasOne(MallOrder::class, ['id' => 'order_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getApply()
- {
- return $this->hasOne(ApplyList::class, ['user_id' => 'user_id'])
- ->andWhere(['status' => ApplyList::PASSED]);
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'from_user_id' => 'From User ID',
- 'level' => 'Level',
- 'goods_name' => 'Goods Name',
- 'goods_price' => 'Goods Price',
- 'order_no' => 'Order No',
- 'commission_level' => 'Commission Level',
- 'order_id' => 'Order ID',
- 'order_detail_id' => 'Order Detail ID',
- 'setting_log_id' => 'Setting Log ID',
- 'commission_amount' => 'Commission Amount',
- 'status' => 'Status',
- 'deleted_at' => 'Deleted At',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- ];
- }
- /**
- * 添加分佣记录
- *
- * @param integer $mall_id
- * @param integer $user_id
- * @param integer $level
- * @param integer $commission_level
- * @param integer $order_id
- * @param integer $order_detail_id
- * @param integer $setting_log_id
- * @param float $commission_amount
- * @return int|static
- */
- public static function addCommissionLog(
- int $mall_id,
- int $user_id,
- int $from_user_id,
- string $goods_name,
- float $goods_price,
- string $order_no,
- int $level,
- int $commission_level,
- int $order_id,
- int $order_detail_id,
- int $setting_log_id,
- float $commission_amount
- )
- {
- $model = new static;
- $model->load(compact(
- 'mall_id',
- 'user_id',
- 'level',
- 'from_user_id',
- 'goods_name',
- 'goods_price',
- 'order_no',
- 'commission_level',
- 'order_id',
- 'order_detail_id',
- 'setting_log_id',
- 'commission_amount'
- ), '');
- $res = $model->save();
- return $res === true
- ? $model->id
- : $model;
- }
- /**
- * 通过订单详情ID查询是否已经创建佣金记录
- *
- * @param integer $order_detail_id
- * @param integer $level
- * @return boolean
- */
- public static function hasCommissonByDetailId(int $order_detail_id, int $level)
- {
- return (boolean) static::find()
- ->andWhere(['order_detail_id' => $order_detail_id, 'commission_level' => $level])
- ->select('id')
- ->scalar();
- }
- /**
- * 获取佣金列表
- *
- * @param integer $order_id
- * @return array
- */
- public static function getLogByOrderId(int $order_id)
- {
- return static::find()
- ->andWhere(['order_id' => $order_id, 'status' => 0])
- ->all();
- }
- /**
- * 获取佣金列表
- *
- * @param integer $order_detail_id
- * @return array
- */
- public static function getLogByOrderDetailId(int $order_detail_id)
- {
- return static::find()
- ->andWhere(['order_detail_id' => $order_detail_id, 'status' => 0])
- ->all();
- }
- /**
- * 修改状态
- *
- * @param array $ids
- * @param integer $status
- * @return void
- */
- public static function changeStatusByIds(array $ids, int $status = 1)
- {
- return static::updateAll(
- ['status' => $status],
- ['id' => $ids]
- );
- }
- }
|