| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%pond_user_num}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $user_id
- * @property integer $status
- * @property string $remark
- * @property integer $create_time
- * @property integer $update_time
- */
- class PondUserNum extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%pond_user_num}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['store_id', 'user_id', 'status', 'create_time', 'update_time'], 'integer'],
- [['remark'], 'safe'],
- ];
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time']
- ]
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => 'Store ID',
- 'user_id' => 'User ID',
- 'status' => ' 0未领取1 已领取',
- 'remark' => 'remark',
- 'create_time' => 'Create Time',
- 'update_time' => '领取时间',
- ];
- }
- public function sendNum($user_id)
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- $time = time();
- $user = User::findOne($user_id);
- if ($user && $user->parent_id) {
- $setting = PondSetting::find()
- ->where(['store_id' => $user->store_id])
- ->andWhere(['<=', 'start_time', $time])
- ->andWhere(['>', 'end_time', $time])
- ->asArray()->one();
- if ($setting) {
- $obj = new self();
- $obj->store_id = $user->store_id;
- $obj->user_id = $user->parent_id;
- $obj->status = 0;
- $obj->remark = '下级用户下单赠送';
- $obj->save();
- }
- }
- $t->commit();
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error($e->getMessage());
- }
- }
- }
|