IntegralRelease.php 4.3 KB
<?php

namespace common\models;

use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "chain_integral_release".
 *
 * @property string $id
 * @property string $uid
 * @property integer $release_type
 * @property integer $type
 * @property string $integral
 * @property integer $status
 * @property string $created_at
 * @property string $updated_at
 */
class IntegralRelease extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%integral_release}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'type', 'status'], 'required'],
            [['uid', 'report_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
            [['price'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => '用户ID',
            'report_id' => '销售中心UID',
            'type' => '类型',
            'price' => '积分',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at',
            ],
        ];
    }


    /**
     * @param $data
     * @return string
     */
    public static function payType($data)
    {
        switch ($data) {
            case 1 :
                return '会员销售';
                break;
            case 2:
                return '推荐';
                break;
            case 21:
                return '推荐';
                break;
            case 3:
                return '出局';
                break;
            case 4:
                return '销售出局奖';
                break;
//            default :
//                return '未知赠送';

        }
    }


    /**
     * @param $data
     * @return string
     */
    public static function releaseType($data)
    {
        switch ($data) {
            case "已释放" :
                return 1;
                break;
            case '未释放':
                return 0;
                break;
//            default :
//                return '未知赠送';
        }
    }

    /**
     * @param $data
     * @return string
     */
    public static function Type($data)
    {
        switch ($data) {
            case "会员销售奖	" :
                return 1;
                break;
            case '推荐奖	':
                return 2;
                break;
            case '出局奖':
                return 3;
                break;

        }
    }

    /**
     * 添加记录
     * @param $data
     * @return int
     * @throws \yii\db\Exception
     */
    public static function add($data)
    {
        $result = \Yii::$app->db->createCommand()->batchInsert(IntegralRelease::tableName(), ['report_id', 'uid', 'type', 'price', 'status', 'created_at', 'updated_at'], $data)->execute();
        return $result;
    }

    /**
     * 查找报单中心订单
     * @param $uid
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function findByReUid($uid, $page)
    {
        $list = self::find()->where(['report_id' => $uid])->andWhere(['type' => 1])->orderBy('id desc')->offset(($page - 1) * 6)->limit(6)->asArray()->all();
        $ls = self::find()->where(['report_id' => $uid])->andWhere(['type' => 1])->count(1);
        if (!empty($list)) {
            foreach ($list as $k => &$value) {
                $user = User::findOne($value['uid']);
//                $value['uid'] = 'HC' . substr($user['mobile'], -6);
                $value['uid'] = $user['id'];
                $value['realname'] = $user['realname'];
                $value['mobile'] = $user['mobile'];
                $value['created_at'] = date("Y-m-d H:i:s", $value['created_at']);
                $value['updated_at'] = date("Y-m-d H:i:s", $value['updated_at']);
            }
        }
        $data['page'] = ceil($ls / 6);
        $data['list'] = $list;
        return $data;
    }

}