Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FxUserAccount.php 4.2 KiB

há 3 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * 数据库表类 fx_user_account
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2017/06/16 10:22 $
  14. */
  15. namespace common\models;
  16. use yii\db\ActiveRecord;
  17. /**
  18. * 数据库表类 fx_user_account.
  19. * @property integer $id
  20. * @property integer $fx_uid
  21. * @property string $available_commission
  22. * @property string $closed_commission
  23. * @property string $total_commission
  24. * @property string $apply_commission
  25. * @property integer $remaining_sum
  26. * @property string $create_time
  27. * @property string $update_time
  28. * @property integer $status
  29. * @property integer $delete_flag
  30. */
  31. class FxUserAccount extends ActiveRecord
  32. {
  33. /**
  34. * @inheritdoc
  35. */
  36. public static function tableName()
  37. {
  38. return 'fx_user_account';
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function rules()
  44. {
  45. return [
  46. [['fx_uid'], 'required'],
  47. [['fx_uid', 'status', 'delete_flag'], 'integer'],
  48. [['available_commission', 'closed_commission', 'total_commission', 'apply_commission', 'remaining_sum'], 'number'],
  49. [['create_time', 'update_time'], 'safe'],
  50. [['fx_uid'], 'unique'],
  51. ];
  52. }
  53. /**
  54. * @inheritdoc
  55. */
  56. public function attributeLabels()
  57. {
  58. return [
  59. 'id' => 'ID',
  60. 'fx_uid' => 'Fx Uid',
  61. 'available_commission' => 'Available Commission',
  62. 'closed_commission' => 'Closed Commission',
  63. 'total_commission' => 'Total Commission',
  64. 'apply_commission' => 'Apply Commission',
  65. 'remaining_sum' => 'Remaining Sum',
  66. 'create_time' => 'Create Time',
  67. 'update_time' => 'Update Time',
  68. 'status' => 'Status',
  69. 'delete_flag' => 'Delete Flag',
  70. ];
  71. }
  72. /**
  73. * Function Description:获取账户信息
  74. * Function Name: getMyCommission
  75. * @param $fx_uid
  76. * @return array
  77. *
  78. * @author 娄梦宁
  79. */
  80. public function getMyCommission($fx_uid)
  81. {
  82. $select = [
  83. 'a.headimgurl',
  84. 'a.phone',
  85. 'a.nickname',
  86. 'b.status as accountStatus',
  87. 'ifnull(b.available_commission,0) available_commission',
  88. 'ifnull(b.total_commission,0) total_commission',
  89. 'ifnull(b.apply_commission,0) apply_commission',
  90. 'FORMAT(ifnull(b.remaining_sum,0),0) remaining_sum_s',
  91. 'b.remaining_sum'
  92. ];
  93. $result = self::find()->select($select)
  94. ->from('fx_user as a')
  95. ->leftJoin(self::tableName() . ' as b', 'a.uid=b.fx_uid')
  96. ->where(['=', 'a.uid', $fx_uid])
  97. ->asArray()
  98. ->one();
  99. return $result;
  100. }
  101. /**
  102. * Des:扣除用户余额
  103. * Name: changeStatus
  104. * @param $fx_uid
  105. * @param $money
  106. * @return bool
  107. * @author 倪宗锋
  108. */
  109. public function deductAmount($fx_uid, $money)
  110. {
  111. $sql = "UPDATE fx_user_account
  112. set remaining_sum=remaining_sum - $money
  113. where fx_uid=$fx_uid
  114. ";
  115. $res = $this->getDb()->createCommand($sql)->execute();
  116. if (!$res) {
  117. return false;
  118. }
  119. return true;
  120. }
  121. /**
  122. * Des:用户余额充值
  123. * Name: changeStatus
  124. * @param $fx_uid
  125. * @param $money
  126. * @return bool
  127. * @author 倪宗锋
  128. */
  129. public function rechargeAmount($fx_uid, $money)
  130. {
  131. $sql = "UPDATE fx_user_account
  132. set remaining_sum=remaining_sum + $money
  133. where fx_uid=$fx_uid
  134. ";
  135. $res = $this->getDb()->createCommand($sql)->execute();
  136. if (!$res) {
  137. return false;
  138. }
  139. return true;
  140. }
  141. }