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] ); } }