HigoHibeiLog.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace addons\HiGo\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_higo_hibei_log}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id
  9. * @property string $change_type 操作类型:add-增加,sub-减少
  10. * @property float $change_num 操作数量
  11. * @property string $desc 变动说明
  12. * @property string $from_type 来源类型
  13. * @property int $status 状态,-1:失效,1:正常,2:冻结
  14. * @property int $created_at 添加时间戳
  15. * @property int $updated_at 更新时间戳
  16. * @property string $setting 系统设置
  17. */
  18. class HigoHibeiLog extends \common\models\base\BaseActiveRecord
  19. {
  20. const FROM_TYPE_AIRDROP = 'airdrop'; //空投
  21. const FROM_TYPE_DESTROY = 'destroy'; //销毁
  22. const FROM_TYPE_TRANSFER_DESTROY = 'transfer_destroy'; //转让销毁
  23. const FROM_TYPE_ORDER = 'order'; // 商城订单赠送
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_higo_hibei_log}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  38. [['change_num'], 'number'],
  39. [['change_type'], 'string', 'max' => 12],
  40. [['desc', 'from_type'], 'string', 'max' => 255],
  41. [['setting'],'string']
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'mall_id' => 'Mall ID',
  52. 'change_type' => 'Change Type',
  53. 'change_num' => 'Change Num',
  54. 'desc' => 'Desc',
  55. 'from_type' => 'From Type',
  56. 'status' => 'Status',
  57. 'created_at' => 'Created At',
  58. 'updated_at' => 'Updated At',
  59. ];
  60. }
  61. /**
  62. * 保存数据
  63. * @Author: zmz
  64. * @DateTime: 2022/11/16 12:13
  65. * @Copyright: copyright (c) 2022 广东七件事集团
  66. * @param array $params
  67. * @return bool
  68. */
  69. public static function setData(array $params){
  70. try{
  71. if(isset($params['id']) && $params['id']) {
  72. $model = self::findOne(['id' => $params['id']]);
  73. if (empty($model)) throw new \Exception('服务不存在或已删除');
  74. }else{
  75. $model = new self();
  76. $model->loadDefaultValues();
  77. }
  78. if(!$model->load($params,'') || !$model->save()){
  79. throw new \Exception($model->getErrorMessage());
  80. }
  81. return $model;
  82. }catch(\Exception $e){
  83. self::setStaticError($e->getMessage());
  84. return false;
  85. }
  86. }
  87. }