IntegralAppreciationTransferIntegralLog.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\db\ActiveRecord;
  9. use yii\behaviors\TimestampBehavior;
  10. /**
  11. * This is the model class for table "{{%integral_appreciation_transfer_integral_log}}".
  12. *
  13. * @property integer $id
  14. * @property integer $user_id
  15. * @property integer $store_id
  16. * @property float $amount
  17. * @property float $transfer_amount
  18. * @property integer $type
  19. * @property float $integral_price
  20. * @property float $fee
  21. * @property string $created_at
  22. * @property string $updated_at
  23. */
  24. class IntegralAppreciationTransferIntegralLog extends \yii\db\ActiveRecord
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%integral_appreciation_transfer_integral_log}}';
  32. }
  33. public function behaviors()
  34. {
  35. return [
  36. [
  37. 'class' => TimestampBehavior::class
  38. ]
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function rules()
  45. {
  46. return [
  47. [['id', 'user_id', 'type','store_id'], 'integer'],
  48. [['amount','transfer_amount','integral_price','fee', 'created_at', 'updated_at'], 'number'],
  49. ];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'id' => '',
  58. 'user_id' => '用户ID',
  59. 'store_id' => '商户ID',
  60. 'amount' => '数量',
  61. 'transfer_amount' => '转换数量',
  62. 'type' => '类型 1积分转余额 2余额转积分',
  63. 'integral_price' => '积分价格',
  64. 'fee' => '手续费',
  65. 'created_at' => '',
  66. 'updated_at' => ''
  67. ];
  68. }
  69. public static function saveIntegralLog($user_id,$store_id, $num,$transfer_amount ,$integral_price, $fee,$type) {
  70. $user = IntegralAppreciationUser::findOne(['user_id'=>$user_id]);
  71. if (!$user) {
  72. return [
  73. 'code' => 1,
  74. 'msg' => '用户不存在'
  75. ];
  76. }
  77. try {
  78. $integral_log = new IntegralAppreciationTransferIntegralLog();
  79. $integral_log->user_id = $user_id;
  80. $integral_log->store_id = $store_id;
  81. $integral_log->amount = $num;
  82. $integral_log->transfer_amount = $transfer_amount;
  83. $integral_log->type = $type;
  84. $integral_log->integral_price = $integral_price;
  85. $integral_log->fee = $fee;
  86. $integral_log->save();
  87. return [
  88. 'code' => 0,
  89. 'msg' => '操作成功'
  90. ];
  91. }catch (\Exception $e){
  92. return [
  93. 'code' => 1,
  94. 'msg' => $e->getMessage()
  95. ];
  96. }
  97. }
  98. }