Withdraw.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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::find()->where(['member_id' => $memberId, 'type' => 0])->asArray()->all();
  102. }
  103. /**
  104. * 获取当月出金记录
  105. * @param int $memberId
  106. * @return array|\yii\db\ActiveRecord[]
  107. */
  108. public static function getMonthWithdraw($memberId)
  109. {
  110. $inTimeStart = strtotime(date('Y-m-01 00:00:00')) * 1000;
  111. $inTimeEnd = (strtotime(date('Y-m-t 00:00:00')) + 86400) * 1000;
  112. return static::find()->where(['member_id' => $memberId])
  113. ->andWhere(['type' => 2])
  114. ->andWhere(['>=', 'in_time', $inTimeStart])
  115. ->andWhere(['<', 'in_time', $inTimeEnd])
  116. ->asArray()->all();
  117. }
  118. /**
  119. * 统计出金金额 amount+fee
  120. * @param int $type
  121. * @return mixed
  122. */
  123. public static function sumWithdrawByType($type)
  124. {
  125. return static::find()->andFilterWhere(['type' => $type])->sum('amount+fee');
  126. }
  127. /**
  128. * 统计出金金额 amount
  129. * @param int $type
  130. * @return mixed
  131. */
  132. public static function sumNotFeeByType($type)
  133. {
  134. return static::find()->andFilterWhere(['type' => $type])->sum('amount');
  135. }
  136. /**
  137. * 统计出金金额 人民币 amount*rate
  138. * @param int $type
  139. * @return mixed
  140. */
  141. public static function sumRmbByType($type)
  142. {
  143. return static::find()->andFilterWhere(['type' => $type])->sum('amount*rate');
  144. }
  145. /**
  146. * 收取手续费,单位美元
  147. * @param float $amount
  148. * @param array $member
  149. * @return float
  150. */
  151. public static function getFee($amount, $member)
  152. {
  153. // 原来的规则,XBroker当月第二次以后出金固定收取25美元,这个规则已废弃
  154. // $monthWithdraw = static::getMonthWithdraw($member['id']);
  155. // $fee = $monthWithdraw ? 25 : 0;
  156. return 5;
  157. // XBroker和XTrader都要收取手续费
  158. $percent = 0.005;
  159. if (function_exists('bcmul')) {
  160. $fee = bcmul($amount, $percent, 3);
  161. } else {
  162. $fee = $amount * $percent;
  163. }
  164. $fee = number_format($fee, 2, '.', '');
  165. return $fee;
  166. }
  167. }