| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * @property integer $id
- * @property integer $sales_id
- * @property integer $user_id
- * @property integer $order_id
- * @property string $order_detail_id
- * @property integer $points
- * @property integer $weight
- * @property integer $parent_id
- * @property integer $parent_user_id
- * @property integer $status
- * @property string $created_at
- * @property string $updated_at
- */
- class SuperSalesSub extends \yii\db\ActiveRecord
- {
- /**
- * 状态:未完结
- */
- const STATUS_NOT_FINISH = 0;
- /**
- * 状态:完结
- */
- const STATUS_FINISH = 1;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%super_sales_sub}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class
- ]
- ];
- }
- public function rules()
- {
- return [
- [['id', 'sales_id', 'user_id', 'order_id', 'points', 'weight', 'parent_id', 'parent_user_id', 'status'], 'integer'],
- [['created_at', 'updated_at', 'order_detail_id'], 'string']
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => '',
- 'sales_id' => '开团表ID',
- 'user_id' => '用户ID',
- 'order_id' => '订单ID',
- 'order_detail_id' => '订单详情ID',
- 'points' => '点位',
- 'weight' => '权重',
- 'parent_id' => '当前位置的上级ID',
- 'parent_user_id' => '上级用户ID',
- 'status' => '状态:0=未完结;1=已完结;',
- 'created_at' => '',
- 'updated_at' => '',
- ];
- }
- public function afterSave($insert, $changedAttributes)
- {
- parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
- if ($insert) {
- $superSales = SuperSales::findOne($this->sales_id);
- if ($superSales) {
- $user = SuperSalesUser::findOne(['user_id' => $this->user_id]);
- if (!$user) {
- $user = new SuperSalesUser();
- $user->store_id = $superSales->store_id;
- $user->user_id = $this->user_id;
- $user->parent_user_id = $this->parent_user_id;
- $user->save();
- }
- }
- }
- }
- }
|