Withdraw.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace backend\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "crm_withdraw".
  6. *
  7. * @property integer $id
  8. * @property integer $type
  9. * @property integer $member_id
  10. * @property string $amount
  11. * @property string $fee
  12. * @property string $memo
  13. * @property integer $in_time
  14. * @property integer $out_time
  15. * @property string $true_name
  16. * @property string $bank_name
  17. * @property string $bank_sub_name
  18. * @property string $bank_card_no
  19. * @property string $bank_province
  20. * @property string $bank_city
  21. * @property string $mobile
  22. * @property integer $login
  23. * @property string $rate
  24. * @property string $swift
  25. * @property string $admin_name
  26. */
  27. class Withdraw extends \yii\db\ActiveRecord
  28. {
  29. /**
  30. * @var array
  31. */
  32. public static $typeTextMap = [
  33. 0 => '等待审核',
  34. 1 => '不通过',
  35. 2 => '已出金',
  36. 3 => '管理员撤销',
  37. 5 => '暂不处理',
  38. 6 => '处理中',
  39. ];
  40. /**
  41. * @inheritdoc
  42. */
  43. public static function tableName()
  44. {
  45. return 'crm_withdraw';
  46. }
  47. /**
  48. * @return \yii\db\Connection the database connection used by this AR class.
  49. */
  50. public static function getDb()
  51. {
  52. return Yii::$app->get('dbXcrm');
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function rules()
  58. {
  59. return [
  60. [['type', 'member_id', 'amount', 'in_time', 'true_name', 'bank_name', 'bank_card_no', 'bank_province', 'bank_city', 'mobile', 'login', 'rate'], 'required'],
  61. [['type', 'member_id', 'in_time', 'out_time', 'login','mt4_status'], 'integer'],
  62. [['amount', 'fee', 'rate'], 'number'],
  63. [['memo', 'true_name', 'bank_name', 'bank_sub_name', 'bank_card_no', 'bank_province', 'bank_city', 'mobile', 'swift', 'admin_name'], 'string', 'max' => 255],
  64. ];
  65. }
  66. /**
  67. * @inheritdoc
  68. */
  69. public function attributeLabels()
  70. {
  71. return [
  72. 'id' => '主键ID',
  73. 'type' => '出金状态(0:等待审核;1:不通过;2:已出金;3:管理员撤销;5:暂不处理;6:处理中)',
  74. 'member_id' => '代理商ID',
  75. 'amount' => '出金金额',
  76. 'fee' => '手续费',
  77. 'memo' => '备注',
  78. 'in_time' => '申请时间',
  79. 'out_time' => '出金时间',
  80. 'true_name' => '姓名',
  81. 'bank_name' => '银行名称',
  82. 'bank_sub_name' => '分行名称',
  83. 'bank_card_no' => '银行卡号',
  84. 'bank_province' => '银行省份',
  85. 'bank_city' => '银行城市',
  86. 'mobile' => '电话号码',
  87. 'login' => 'mt4登录ID',
  88. 'rate' => '汇率',
  89. 'swift' => 'Swift',
  90. 'mt4_status' => 'mt4出金状态',
  91. 'admin_name' => '操作人',
  92. ];
  93. }
  94. /**
  95. * 获取未处理的出金记录
  96. * @param int $memberId
  97. * @return array|\yii\db\ActiveRecord[]
  98. */
  99. public static function getUnDealList($memberId)
  100. {
  101. //return static::hasMany(Mt4DepositLog::className(), ['id' => 'log_id'])->asArray()->all(); //新建联表
  102. return static::find()->where(['member_id' => $memberId, 'type' => 6])->asArray()->all(); //原来的代码
  103. }
  104. /**
  105. * 获取当月出金记录
  106. * @param int $memberId
  107. * @return array|\yii\db\ActiveRecord[]
  108. */
  109. public static function getMonthWithdraw($memberId)
  110. {
  111. $inTimeStart = strtotime(date('Y-m-01 00:00:00')) * 1000;
  112. $inTimeEnd = (strtotime(date('Y-m-t 00:00:00')) + 86400) * 1000;
  113. return static::find()->where(['member_id' => $memberId])
  114. ->andWhere(['type' => 2])
  115. ->andWhere(['>=', 'in_time', $inTimeStart])
  116. ->andWhere(['<', 'in_time', $inTimeEnd])
  117. ->asArray()->all();
  118. }
  119. /**
  120. * 统计出金金额 amount+fee
  121. * @param int $type
  122. * @return mixed
  123. */
  124. public static function sumWithdrawByType($type)
  125. {
  126. return static::find()->andFilterWhere(['type' => $type])->sum('amount+fee');
  127. }
  128. /**
  129. * 统计出金金额 amount
  130. * @param int $type
  131. * @return mixed
  132. */
  133. public static function sumNotFeeByType($type)
  134. {
  135. return static::find()->andFilterWhere(['type' => $type])->sum('amount');
  136. }
  137. /**
  138. * 统计出金金额 人民币 amount*rate
  139. * @param int $type
  140. * @return mixed
  141. */
  142. public static function sumRmbByType($type)
  143. {
  144. return static::find()->andFilterWhere(['type' => $type])->sum('amount*rate');
  145. }
  146. /**
  147. * 收取手续费,单位美元
  148. * @param float $amount
  149. * @param array $member
  150. * @return float
  151. */
  152. public static function getFee($amount, $member)
  153. {
  154. // 原来的规则,XBroker当月第二次以后出金固定收取25美元,这个规则已废弃
  155. // $monthWithdraw = static::getMonthWithdraw($member['id']);
  156. // $fee = $monthWithdraw ? 25 : 0;
  157. return 5;
  158. // XBroker和XTrader都要收取手续费
  159. $percent = 0.005;
  160. if (function_exists('bcmul')) {
  161. $fee = bcmul($amount, $percent, 3);
  162. } else {
  163. $fee = $amount * $percent;
  164. }
  165. $fee = number_format($fee, 2, '.', '');
  166. return $fee;
  167. }
  168. }