CloudStockTwoBuyingOrder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace addons\CloudStockTwo\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\goods\Goods;
  6. use common\models\order\Order;
  7. use common\models\order\OrderDetail;
  8. use common\models\user\User;
  9. use Yii;
  10. /**
  11. * This is the model class for table "{{%addons_cloud_stock_buying_order".
  12. *
  13. * @property int $id 自增id
  14. * @property int $mall_id 商城id
  15. * @property int $user_id 买货用户id
  16. * @property float $after_distribution_price 商品的实际支付金额扣除其他分润后的金额;未扣奖励前货款;
  17. * @property int $order_id 订单id;order表
  18. * @property int $order_detail_id 订单详情id;order_detail表
  19. * @property int $goods_id 商品id
  20. * @property int $num 商品数量
  21. * @property int $is_return 是否有退库存
  22. * @property int $status 状态[-1:删除;0:禁用;1启用]
  23. * @property int $created_at
  24. * @property int $updated_at
  25. */
  26. class CloudStockTwoBuyingOrder extends BaseActiveRecord
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%addons_cloud_stock_two_buying_order}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['mall_id', 'user_id', 'goods_id', 'num'], 'required'],
  42. [['mall_id', 'user_id', 'order_id', 'order_detail_id', 'goods_id', 'num', 'is_return', 'status', 'created_at', 'updated_at'], 'integer'],
  43. [['after_distribution_price','reward_unit_price'], 'number'],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => '自增id',
  53. 'mall_id' => '商城id',
  54. 'user_id' => '买货用户id',
  55. 'after_distribution_price' => '商品的实际支付金额扣除其他分润后的金额;未扣奖励前货款;',
  56. 'order_id' => '订单id;order表',
  57. 'order_detail_id' => '订单详情id;order_detail表',
  58. 'goods_id' => '商品id',
  59. 'num' => '商品数量',
  60. 'is_return' => '是否有退库存',
  61. 'status' => '状态[-1:删除;0:禁用;1启用]',
  62. 'created_at' => 'Created At',
  63. 'updated_at' => 'Updated At',
  64. 'reward_unit_price' => 'Reward Unit Price',
  65. ];
  66. }
  67. public function getUser()
  68. {
  69. return $this->hasOne(User::class, ['id' => 'user_id'])->select(['id', 'nickname', 'avatar_url', 'mobile']);
  70. }
  71. public function getOrder()
  72. {
  73. return $this->hasOne(Order::class, ['id' => 'order_id'])->select(['order_no', 'order_status', 'id','is_feedback','pay_money']);
  74. }
  75. public function getOrderDetail()
  76. {
  77. return $this->hasOne(OrderDetail::class, ['id' => 'order_detail_id'])->select(['price', 'is_feedback', 'id']);
  78. }
  79. public function getGoods()
  80. {
  81. return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select(['id', 'goods_name', 'cover_pic']);
  82. }
  83. public static function setData(array $params)
  84. {
  85. try {
  86. if(!empty($params['id'])){
  87. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
  88. if (empty($model)) throw new \Exception('服务不存在或已删除');
  89. }else{
  90. $model = new self();
  91. $model->loadDefaultValues();
  92. }
  93. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  94. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  95. return $model;
  96. } catch (\Exception $e) {
  97. self::$static_error = $e->getMessage();
  98. return false;
  99. }
  100. }
  101. }