WriteOffMemberLog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace addons\WriteOff\common\models;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. /**
  6. * This is the model class for table "{{%addons_write_off_member_log}}".
  7. *
  8. * @property int $id ID
  9. * @property int $mall_id 商城ID
  10. * @property int $setting_id 设置ID
  11. * @property int $goods_id 商品ID
  12. * @property int $user_id 用户ID
  13. * @property float $change_num 操作数量
  14. * @property float $current_num 当前数量
  15. * @property string $order_no 订单号
  16. * @property string $source_table 来源表
  17. * @property int $source_table_id 操作来源业务id
  18. * @property string $desc 说明
  19. * @property int $status 状态[-1删除; 0禁用; 1正常]
  20. * @property int $created_at 创建时间
  21. * @property int $updated_at 更新时间
  22. */
  23. class WriteOffMemberLog extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_write_off_member_log}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'setting_id', 'goods_id', 'user_id', 'source_table_id', 'status', 'created_at', 'updated_at','store_id','code'], 'integer'],
  39. [['change_num', 'current_num'], 'number'],
  40. [['order_no'], 'string', 'max' => 64],
  41. [['change_type'], 'string', 'max' => 12],
  42. [['source_table', 'desc'], 'string', 'max' => 255],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'ID',
  52. 'mall_id' => 'Mall ID',
  53. 'setting_id' => 'Setting ID',
  54. 'goods_id' => 'Goods ID',
  55. 'user_id' => 'User ID',
  56. 'change_num' => 'Change Num',
  57. 'current_num' => 'Current Num',
  58. 'order_no' => 'Order No',
  59. 'source_table' => 'Source Table',
  60. 'source_table_id' => 'Source Table ID',
  61. 'desc' => 'Desc',
  62. 'status' => 'Status',
  63. 'created_at' => 'Created At',
  64. 'updated_at' => 'Updated At',
  65. 'change_type' => 'Change Type',
  66. 'store_id' => 'Store Id',
  67. ];
  68. }
  69. /**
  70. * 保存数据
  71. * @Author: lun
  72. * @DateTime: 2021/10/20 0020 18:01
  73. * @Copyright: copyright (c) 2021 广东七件事集团
  74. * @param array $params
  75. * @return AddonsBossLevel|bool
  76. */
  77. public static function setData(array $params){
  78. $trans = Yii::$app->db->beginTransaction();
  79. try{
  80. if(!empty($params['id'])){
  81. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $params['mall_id']],['<>','status',StatusEnum::DELETE]]);
  82. if(empty($model)) throw new \Exception('数据不存在或已删除');
  83. }else{
  84. $model = new self();
  85. $model->loadDefaultValues();
  86. $model->mall_id = $params['mall_id'];
  87. }
  88. if(!$model->load($params,'') || !$model->save()){
  89. throw new \Exception($model->getErrorMessage());
  90. }
  91. $trans->commit();
  92. return $model;
  93. }catch(\Exception $e){
  94. $trans->rollBack();
  95. self::$static_error = $e->getMessage();
  96. return false;
  97. }
  98. }
  99. }