| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace addons\CloudStockTwo\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\goods\Goods;
- use common\models\order\Order;
- use common\models\order\OrderDetail;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_cloud_stock_buying_order".
- *
- * @property int $id 自增id
- * @property int $mall_id 商城id
- * @property int $user_id 买货用户id
- * @property float $after_distribution_price 商品的实际支付金额扣除其他分润后的金额;未扣奖励前货款;
- * @property int $order_id 订单id;order表
- * @property int $order_detail_id 订单详情id;order_detail表
- * @property int $goods_id 商品id
- * @property int $num 商品数量
- * @property int $is_return 是否有退库存
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class CloudStockTwoBuyingOrder extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_two_buying_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'goods_id', 'num'], 'required'],
- [['mall_id', 'user_id', 'order_id', 'order_detail_id', 'goods_id', 'num', 'is_return', 'status', 'created_at', 'updated_at'], 'integer'],
- [['after_distribution_price','reward_unit_price'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '自增id',
- 'mall_id' => '商城id',
- 'user_id' => '买货用户id',
- 'after_distribution_price' => '商品的实际支付金额扣除其他分润后的金额;未扣奖励前货款;',
- 'order_id' => '订单id;order表',
- 'order_detail_id' => '订单详情id;order_detail表',
- 'goods_id' => '商品id',
- 'num' => '商品数量',
- 'is_return' => '是否有退库存',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'reward_unit_price' => 'Reward Unit Price',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select(['id', 'nickname', 'avatar_url', 'mobile']);
- }
- public function getOrder()
- {
- return $this->hasOne(Order::class, ['id' => 'order_id'])->select(['order_no', 'order_status', 'id','is_feedback','pay_money']);
- }
- public function getOrderDetail()
- {
- return $this->hasOne(OrderDetail::class, ['id' => 'order_detail_id'])->select(['price', 'is_feedback', 'id']);
- }
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select(['id', 'goods_name', 'cover_pic']);
- }
- public static function setData(array $params)
- {
- try {
- if(!empty($params['id'])){
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|