BusinessCardTask.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\BusinessCard\common\models;
  3. use common\enums\StatusEnum;
  4. use Exception;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_business_card_task".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property int $last_id 上次执行id
  12. * @property int $total_num 上次执行条数
  13. * @property int $status 状态[1启用 0禁用 -1删除]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 更新事件
  16. */
  17. class BusinessCardTask extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return 'qimall_addons_business_card_task';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'last_id', 'total_num', 'status', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'last_id' => 'Last ID',
  44. 'total_num' => 'Total Num',
  45. 'status' => 'Status',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. ];
  49. }
  50. /**
  51. * 保存数据
  52. *
  53. * @author ltm
  54. * @return bool|Exception
  55. */
  56. public static function setData($params) {
  57. try {
  58. if (empty($params['id'])) {
  59. $model = new self();
  60. } else {
  61. $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  62. if (empty($model)) throw new \Exception('数据不存在或者已删除');
  63. }
  64. if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
  65. return $model->id;
  66. } catch (\Exception $e) {
  67. self::$static_error = $e->getMessage();
  68. return false;
  69. }
  70. }
  71. }