| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace common\models\user;
- use common\models\base\BaseActiveRecord;
- use common\models\order\Order;
- use Yii;
- /**
- * This is the model class for table "{{%user_team_achievement_order_1}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 下单会员ID
- * @property int $order_id 订单ID
- * @property int $superior_user_id 团队上级会员ID
- * @property int $superior_level 上级级别
- * @property int $status 1 已支付 2 已完成
- * @property int|null $created_at
- */
- class UserTeamAchievementOrder extends BaseActiveRecord
- {
- /**
- * @var integer
- */
- protected static $tb = 0;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_team_achievement_order_' . static::$tb .'}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'order_id', 'superior_user_id', 'superior_level', 'status'], 'required'],
- [['mall_id', 'user_id', 'order_id', 'superior_user_id', 'superior_level', 'status', 'created_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'order_id' => 'Order ID',
- 'superior_user_id' => 'Superior User ID',
- 'superior_level' => 'Superior Level',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- ];
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getOrder()
- {
- return $this->hasOne(Order::class, ['id' => 'order_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- /**
- * 批量添加
- *
- * @param array $data
- * @return void
- */
- public static function batchInsertData(array $data)
- {
- $insert_data = [];
- foreach ($data as $item) {
- $insert_data[static::sliceRule($item['superior_user_id'])][] = $item;
- }
- foreach ($insert_data as $tb => $items) {
- static::find()
- ->createCommand()
- ->batchInsert(static::getTb($tb), array_keys(reset($items)), $items)->execute();
- }
- }
- /**
- * 切割规则
- *
- * @param integer $user_id
- * @return int
- */
- protected static function sliceRule(int $user_id)
- {
- return $user_id % 10 ? $user_id % 10 : 10;
- }
- /**
- * 获取tb
- *
- * @param integer $tb
- * @return string
- */
- protected static function getTb(int $tb)
- {
- return '{{%user_team_achievement_order_' . $tb . '}}';
- }
- /**
- * 删除改站点相关数据
- *
- * @param integer $mall_id
- * @return void
- */
- public static function deleteMall(int $mall_id)
- {
- for ($i = 1; $i <= 10; $i++) {
- static::$tb = $i;
- static::deleteAll(['mall_id' => $mall_id]);
- }
- }
- /**
- * 获取列表
- *
- * @param integer $limit
- * @param callable|null $callback
- * @param string $order_by
- * @return array
- */
- public static function getPaginationListByUid(
- int $uid, int $limit, callable $callback = null, string $order_by = 'id'
- ): array
- {
- static::$tb = static::sliceRule($uid);
- return static::getPaginationList($limit, $callback, $order_by);
- }
- public static function getTeamAchievementList(int $uid, array $where)
- {
- static::$tb = static::sliceRule($uid);
- return static::find()->where($where);
- }
- }
|