CloudStockBatchFillOrder.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace addons\CloudStock\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\common\PaymentTrade;
  5. use Exception;
  6. use RuntimeException;
  7. use Yii;
  8. /**
  9. * This is the model class for table "qimall_addons_cloud_stock_batch_fill_order".
  10. *
  11. * @property int $id
  12. * @property int $mall_id
  13. * @property int $user_id
  14. * @property int $trade_id 支付流水ID
  15. * @property string $trade_no 支付流水号
  16. * @property string|null $full_order_info 单件补货订单返回值
  17. * @property int $status
  18. * @property int $created_at
  19. * @property int $updated_at
  20. */
  21. class CloudStockBatchFillOrder extends \common\models\base\BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return 'qimall_addons_cloud_stock_batch_fill_order';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id', 'user_id', 'trade_id', 'status', 'created_at', 'updated_at'], 'integer'],
  37. [['full_order_info'], 'safe'],
  38. [['trade_no'], 'string', 'max' => 100],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => 'Mall ID',
  49. 'user_id' => 'User ID',
  50. 'trade_id' => 'Trade ID',
  51. 'trade_no' => 'Trade No',
  52. 'full_order_info' => 'Full Order Info',
  53. 'status' => 'Status',
  54. 'created_at' => 'Created At',
  55. 'updated_at' => 'Updated At',
  56. ];
  57. }
  58. public static function setData(array $params)
  59. {
  60. try {
  61. if(!empty($params['id'])){
  62. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
  63. if (!$model) {
  64. throw new RuntimeException('数据不存在或已删除');
  65. }
  66. }else{
  67. $model = new self();
  68. $model->loadDefaultValues();
  69. }
  70. if (!$model->load($params, '')) throw new Exception($model->getErrorMessage());
  71. if (!$model->save()) throw new Exception($model->getErrorMessage());
  72. return $model;
  73. } catch (Exception $e) {
  74. self::$static_error = $e->getMessage();
  75. return false;
  76. }
  77. }
  78. public function getFillOrders()
  79. {
  80. return $this->hasMany(CloudStockFillOrder::class, ['batch_fill_order_id' => 'id']);
  81. }
  82. public function getPaymentTrade()
  83. {
  84. return $this->hasOne(PaymentTrade::class, ['id' => 'trade_id']);
  85. }
  86. }