CloudStockTwoFillOrder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_fill_order".
  12. *
  13. * @property int $id
  14. * @property int $mall_id 商城id
  15. * @property int $user_id 补货代理商用户id
  16. * @property int $trade_id 支付流水记录 id
  17. * @property float $pay_money 支付金额
  18. * @property string $order_no 补货订单编号
  19. * @property string $trade_no 支付流水号
  20. * @property int $is_pay 是否支付
  21. * @property int $goods_id 商品id
  22. * @property int $num 补货商品数量
  23. * @property int $status 状态[-1:删除;0:禁用;1启用]
  24. * @property int $created_at
  25. * @property int $updated_at
  26. */
  27. class CloudStockTwoFillOrder extends BaseActiveRecord
  28. {
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public static function tableName()
  33. {
  34. return '{{%addons_cloud_stock_two_fill_order}}';
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['mall_id', 'user_id', 'order_no', 'goods_id'], 'required'],
  43. [['mall_id', 'user_id', 'trade_id', 'is_pay', 'goods_id', 'num', 'status', 'created_at', 'updated_at'], 'integer'],
  44. [['pay_money','reward_unit_price'], 'number'],
  45. [['order_no', 'trade_no'], 'string', 'max' => 255],
  46. ];
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'mall_id' => '商城id',
  56. 'user_id' => '补货代理商用户id',
  57. 'trade_id' => '支付流水记录 id',
  58. 'pay_money' => '支付金额',
  59. 'order_no' => '补货订单编号',
  60. 'trade_no' => '支付流水号',
  61. 'is_pay' => '是否支付',
  62. 'goods_id' => '商品id',
  63. 'num' => '补货商品数量',
  64. 'status' => '状态[-1:删除;0:禁用;1启用]',
  65. 'created_at' => 'Created At',
  66. 'updated_at' => 'Updated At',
  67. 'reward_unit_price' => 'Reward Unit Price',
  68. ];
  69. }
  70. public function getUser()
  71. {
  72. return $this->hasOne(User::class, ['id' => 'user_id'])->select(['id', 'nickname', 'avatar_url', 'mobile']);
  73. }
  74. public function getGoods()
  75. {
  76. return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select(['id', 'goods_name', 'cover_pic']);
  77. }
  78. public static function setData(int $mall_id, array $data)
  79. {
  80. if (!empty($data['id'])) {
  81. $model = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]);
  82. if (empty($model)) {
  83. self::$static_error = '数据异常';
  84. return false;
  85. }
  86. } else {
  87. $model = new self();
  88. $model->loadDefaultValues();
  89. $model->mall_id = $mall_id;
  90. }
  91. foreach ($data as $key => $val) {
  92. $model->$key = $val;
  93. }
  94. // dd($model);
  95. if (!$model->save()) {
  96. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  97. return false;
  98. }
  99. return $model;
  100. }
  101. public static function check($params): bool
  102. {
  103. $order_no_arr = $params['order_no_arr'];
  104. $payment_order_list = $params['payment_order_list'];
  105. $counts = self::find()->where(['order_no'=>$order_no_arr,'is_pay'=>0])->count();
  106. if ($counts != count($payment_order_list)) {
  107. self::$static_error = '补货订单不一致';
  108. return false;
  109. }
  110. return true;
  111. }
  112. }