SuperSalesSub.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\models;
  3. use yii\behaviors\TimestampBehavior;
  4. use yii\db\ActiveRecord;
  5. /**
  6. * @property integer $id
  7. * @property integer $sales_id
  8. * @property integer $user_id
  9. * @property integer $order_id
  10. * @property string $order_detail_id
  11. * @property integer $points
  12. * @property integer $weight
  13. * @property integer $parent_id
  14. * @property integer $parent_user_id
  15. * @property integer $status
  16. * @property string $created_at
  17. * @property string $updated_at
  18. */
  19. class SuperSalesSub extends \yii\db\ActiveRecord
  20. {
  21. /**
  22. * 状态:未完结
  23. */
  24. const STATUS_NOT_FINISH = 0;
  25. /**
  26. * 状态:完结
  27. */
  28. const STATUS_FINISH = 1;
  29. /**
  30. * @inheritdoc
  31. */
  32. public static function tableName()
  33. {
  34. return '{{%super_sales_sub}}';
  35. }
  36. public function behaviors()
  37. {
  38. return [
  39. [
  40. 'class' => TimestampBehavior::class
  41. ]
  42. ];
  43. }
  44. public function rules()
  45. {
  46. return [
  47. [['id', 'sales_id', 'user_id', 'order_id', 'points', 'weight', 'parent_id', 'parent_user_id', 'status'], 'integer'],
  48. [['created_at', 'updated_at', 'order_detail_id'], 'string']
  49. ];
  50. }
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => '',
  55. 'sales_id' => '开团表ID',
  56. 'user_id' => '用户ID',
  57. 'order_id' => '订单ID',
  58. 'order_detail_id' => '订单详情ID',
  59. 'points' => '点位',
  60. 'weight' => '权重',
  61. 'parent_id' => '当前位置的上级ID',
  62. 'parent_user_id' => '上级用户ID',
  63. 'status' => '状态:0=未完结;1=已完结;',
  64. 'created_at' => '',
  65. 'updated_at' => '',
  66. ];
  67. }
  68. public function afterSave($insert, $changedAttributes)
  69. {
  70. parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
  71. if ($insert) {
  72. $superSales = SuperSales::findOne($this->sales_id);
  73. if ($superSales) {
  74. $user = SuperSalesUser::findOne(['user_id' => $this->user_id]);
  75. if (!$user) {
  76. $user = new SuperSalesUser();
  77. $user->store_id = $superSales->store_id;
  78. $user->user_id = $this->user_id;
  79. $user->parent_user_id = $this->parent_user_id;
  80. $user->save();
  81. }
  82. }
  83. }
  84. }
  85. }