AreaOrder.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace addons\Area\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\order\OrderDetail;
  6. use Yii;
  7. /**
  8. * This is the model class for table "{{%addons_area_order".
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城ID
  12. * @property int $user_id 会员id
  13. * @property int $order_id 订单id
  14. * @property string $table_name 表名
  15. * @property int $order_detail_id 订单详情id
  16. * @property string $order_no 订单编号
  17. * @property float $in_pool_money 进入分红池金额
  18. * @property int $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at
  20. * @property int $updated_at
  21. */
  22. class AreaOrder extends BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_area_order}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'user_id'], 'required'],
  38. [['mall_id', 'user_id', 'level','status', 'created_at', 'updated_at', 'area_id', 'is_pay', 'pay_time'], 'integer'],
  39. [['price', 'total_commission', 'commission'], 'number'],
  40. [['order_no', 'out_trade_no'], 'string', 'max' => 100],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => 'Mall ID',
  51. 'user_id' => 'User ID',
  52. 'order_id' => 'Order ID',
  53. 'table_name' => 'table_name',
  54. 'order_detail_id' => 'order_detail_id',
  55. 'order_no' => 'Order No',
  56. 'in_pool_money' => 'In Pool Money',
  57. 'status' => 'Status',
  58. 'created_at' => 'Created At',
  59. 'updated_at' => 'Updated At',
  60. ];
  61. }
  62. public static function setData(array $params)
  63. {
  64. try {
  65. if (!empty($params['id'])) {
  66. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  67. if (empty($model)) throw new \Exception('数据不存在或已删除');
  68. } else {
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. }
  72. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  73. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  74. return $model;
  75. } catch (\Exception $e) {
  76. self::$static_error = $e->getMessage();
  77. return false;
  78. }
  79. }
  80. }