You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

107 lines
2.6 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: admin
  5. * Date: 2017/5/4
  6. * Time: 11:47
  7. */
  8. namespace common\models;
  9. use common\util\Util;
  10. use yii\db\ActiveRecord;
  11. use yii\db\Expression;
  12. class FxUserAmountLog extends ActiveRecord
  13. {
  14. public static function tableName()
  15. {
  16. return 'fx_user_amount_log';
  17. }
  18. /**
  19. * @inheritdoc
  20. */
  21. public function rules()
  22. {
  23. return [
  24. [['log_id', 'fx_uid', 'trade_type'], 'integer'],
  25. [['amount', 'remaining_sum'], 'number'],
  26. [['create_time', 'update_time'], 'safe'],
  27. [['msg'], 'string', 'max' => 255],
  28. ];
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function attributeLabels()
  34. {
  35. return [
  36. 'log_id' => 'log_id',
  37. 'fx_uid' => 'fx_uid',
  38. 'amount' => 'amount',
  39. 'remaining_sum' => 'remaining_sum',
  40. 'trade_type' => 'trade_type',
  41. 'create_time' => 'create_time',
  42. 'update_time' => 'Update Time',
  43. 'msg' => 'msg',
  44. ];
  45. }
  46. /**
  47. * 添加记录
  48. * @param $fx_uid
  49. * @param $trade_type
  50. * @param $amount
  51. * @param $msg
  52. * @return array
  53. */
  54. public function addLog($fx_uid, $trade_type, $amount, $remaining_sum, $msg)
  55. {
  56. $param = [
  57. 'fx_uid' => $fx_uid,
  58. 'amount' => $amount,
  59. 'trade_type' => $trade_type,
  60. 'remaining_sum' => $remaining_sum,
  61. 'create_time' => date('Y-m-d H:i:s'),
  62. 'msg' => $msg
  63. ];
  64. $this->attributes = $param;
  65. $insertFlag = $this->insert();
  66. if (!$insertFlag) {
  67. return Util::returnArrEr('add amount_log fail!');
  68. }
  69. return Util::returnArrSu();
  70. }
  71. /**
  72. * 获取账户变更记录
  73. * @param $params
  74. * @return array
  75. */
  76. public function getList($params)
  77. {
  78. $offset = ($params['current_page'] - 1) * $params['page_size'];
  79. $select = [
  80. new Expression('FORMAT(amount,0) as amount'),
  81. 'trade_type',
  82. new Expression('FORMAT(remaining_sum,0) as remaining_sum'),
  83. 'create_time',
  84. new Expression("if(trade_type=1,'充值',if(trade_type=2,'支出','退款')) as type_name")
  85. ];
  86. $where = ['=', 'fx_uid', $params['fx_uid']];
  87. $result = self::find()->select($select)
  88. ->from(self::tableName())
  89. ->where($where)
  90. ->orderBy('create_time DESC')
  91. ->offset($offset)
  92. ->limit($params['page_size'])
  93. ->asArray()
  94. ->all();
  95. return $result;
  96. }
  97. }