DoubleCopyChangePos.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace addons\DoubleCopy\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%addons_double_copy_change_pos}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property string|null $content 交换内容
  12. * @property int|null $change_status 交换状态[-1=交换失败,0=交换中,1=交换成功]
  13. * @property string|null $reason 失败原因
  14. * @property int $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int|null $created_at 创建时间
  16. * @property int|null $updated_at 更新时间
  17. */
  18. class DoubleCopyChangePos extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_double_copy_change_pos}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'change_status', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['content','reason'], 'string'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => '商城ID',
  45. 'content' => '交换内容',
  46. 'change_status' => '交换状态[-1=交换失败,0=交换中,1=交换成功]',
  47. 'reason' => '失败原因',
  48. 'status' => '状态[-1:删除;0:禁用;1启用]',
  49. 'created_at' => '创建时间',
  50. 'updated_at' => '更新时间',
  51. ];
  52. }
  53. /**
  54. * 检测是否还有为完成的提交
  55. * @Author: lun
  56. * @DateTime: 2023/6/3 0003 11:47
  57. * @Copyright: copyright (c) 2021 广东七件事集团
  58. * @param $mall_id
  59. * @return bool
  60. */
  61. public static function check($mall_id)
  62. {
  63. $data = self::find()->where(['mall_id' => $mall_id, 'change_status' => StatusEnum::DISABLED, 'status' => StatusEnum::ENABLED])->asArray()->one();
  64. if ($data) return false;
  65. return true;
  66. }
  67. /**
  68. * 保存数据
  69. * @Author: lun
  70. * @DateTime: 2023/6/3 0003 11:45
  71. * @Copyright: copyright (c) 2021 广东七件事集团
  72. * @param $mall_id
  73. * @param $params
  74. * @return bool|int
  75. */
  76. public static function setData($mall_id, $params)
  77. {
  78. try {
  79. $model = new self();
  80. $model->loadDefaultValues();
  81. $model->mall_id = $mall_id;
  82. $model->content = json_encode($params);
  83. if (!$model->save()) throw new Exception($model->getErrorMessage());
  84. return $model->id;
  85. } catch (\Exception $e) {
  86. self::setStaticError($e->getMessage());
  87. return false;
  88. }
  89. }
  90. }