CloudStockImportStockLog.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace addons\CloudStock\common\models;
  3. use common\models\base\BaseActiveRecord;
  4. use PHPUnit\Util\Exception;
  5. use Yii;
  6. /**
  7. * This is the model class for table "addons_cloud_stock_import_stock_log".
  8. *
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城ID
  12. * @property int $counts 导入数量
  13. * @property int $success_counts 导入成功数量
  14. * @property int $fail_counts 导入失败数量
  15. * @property int $status 状态:1:导入成功;2导入失败;3:导入中;4:导入中断
  16. * @property int $updated_at
  17. * @property int $created_at
  18. */
  19. class CloudStockImportStockLog extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_cloud_stock_import_stock_log}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mall_id', 'counts', 'success_counts', 'fail_counts', 'status', 'updated_at', 'created_at'], 'integer'],
  35. [['upload_file'], 'string'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'mall_id' => '商城ID',
  46. 'counts' => '导入数量',
  47. 'success_counts' => '导入成功数量',
  48. 'fail_counts' => '导入失败数量',
  49. 'status' => '状态:1:导入成功;2导入失败;3:导入中;4:导入中断',
  50. 'updated_at' => 'Updated At',
  51. 'created_at' => 'Created At',
  52. ];
  53. }
  54. /**
  55. * 保存数据
  56. * @param array $params
  57. * @return bool|object
  58. */
  59. public static function setData(array $params)
  60. {
  61. try {
  62. $model = new self();
  63. $model->loadDefaultValues();
  64. empty($fail_counts) ? $param['status'] = 1 : $param['status'] = 2;
  65. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  66. return $model;
  67. } catch (Exception $e) {
  68. self::$static_error = $e->getMessage();
  69. return false;
  70. }
  71. }
  72. }