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.
 
 
 
 
 

191 lines
5.7 KiB

  1. <?php
  2. namespace common\models;
  3. use admin\util\AdminUtil;
  4. use fx\util\FxUtil;
  5. use Yii;
  6. use yii\base\Exception;
  7. use yii\db\Expression;
  8. /**
  9. * This is the model class for table "fx_commission_apply".
  10. *
  11. * @property integer $id
  12. * @property integer $fx_uid
  13. * @property string $apply_money
  14. * @property integer $status
  15. * @property string $remit_time
  16. * @property string $auth_time
  17. * @property string $auth_memo
  18. * @property integer $auth_uid
  19. * @property integer $remit_uid
  20. * @property integer $delete_flag
  21. * @property string $create_time
  22. * @property string $update_time
  23. * @property string $update_user
  24. */
  25. class FxCommissionApply extends \yii\db\ActiveRecord
  26. {
  27. /**
  28. * @inheritdoc
  29. */
  30. public static function tableName()
  31. {
  32. return 'fx_commission_apply';
  33. }
  34. /**
  35. * @inheritdoc
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['fx_uid'], 'required'],
  41. [['fx_uid', 'status', 'auth_uid', 'remit_uid', 'delete_flag'], 'integer'],
  42. [['apply_money'], 'number'],
  43. [['create_time', 'update_time'], 'safe'],
  44. [['remit_time', 'auth_time', 'update_user'], 'string', 'max' => 50],
  45. [['auth_memo'], 'string', 'max' => 255],
  46. ];
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'fx_uid' => 'Fx Uid',
  56. 'apply_money' => 'Apply Money',
  57. 'status' => 'Status',
  58. 'remit_time' => 'Remit Time',
  59. 'auth_time' => 'Auth Time',
  60. 'auth_memo' => 'Auth Memo',
  61. 'auth_uid' => 'Auth Uid',
  62. 'remit_uid' => 'Remit Uid',
  63. 'delete_flag' => 'Delete Flag',
  64. 'create_time' => 'Create Time',
  65. 'update_time' => 'Update Time',
  66. 'update_user' => 'Update User',
  67. ];
  68. }
  69. /**
  70. * Function Description:提现明细
  71. * Function Name: getCommissionApplyList
  72. *
  73. * @return array|\yii\db\ActiveRecord[]
  74. *
  75. * @author 娄梦宁
  76. */
  77. public function getCommissionApplyList(){
  78. $fx_uid=FxUtil::$uid;
  79. $result=self::find()->select(['apply_money','status','date_format(create_time,"%m-%d %H:%i:%s") as create_date',"if(`status`=1,'未审核','已审核') as status_desc"])
  80. ->from(self::tableName())
  81. ->where(['and',['=','fx_uid',$fx_uid],['=','delete_flag',0]])
  82. ->asArray()
  83. ->all();
  84. return $result;
  85. }
  86. /**
  87. * Function Description:提交提现申请,申请表记录
  88. * Function Name: InsertApplyCommission
  89. * @param $apply_commission
  90. *
  91. * @return bool
  92. *
  93. * @author 娄梦宁
  94. */
  95. public function InsertApplyCommission($apply_commission){
  96. $values=[
  97. 'status'=>1,
  98. 'apply_money'=>$apply_commission,
  99. 'fx_uid'=>FxUtil::$uid,
  100. 'create_time'=>date('Y-m-d H:i:s'),
  101. ];
  102. $transaction=Yii::$app->db->beginTransaction();
  103. try{
  104. $this->attributes=$values;
  105. $res=$this->insert();
  106. if(!$res){
  107. throw new Exception('添加出错');
  108. }
  109. $transaction->commit();
  110. return true;
  111. }catch (Exception $e){
  112. $transaction->rollBack();
  113. return false;
  114. }
  115. }
  116. /**
  117. * Function Description:后台提现列表
  118. * Function Name: ApplyList
  119. * @param $param
  120. *
  121. * @return array
  122. *
  123. * @author 娄梦宁
  124. */
  125. public function ApplyList($param){
  126. $where=['and',['=','a.delete_flag',0]];
  127. if ($param['apply_user_name'] != '') {
  128. $where[] = ['like', 'b.nickname', $param['apply_user_name']];
  129. }
  130. if ($param['apply_user_phone'] != '') {
  131. $where[] = ['like', 'b.phone', $param['apply_user_phone']];
  132. }
  133. if ($param['start_time'] != '') {
  134. $where[] = ['>=', 'a.create_time', $param['start_time']];
  135. }
  136. if ($param['end_time'] != '') {
  137. $where[] = ['<', 'a.create_time', date('Y-m-d',strtotime("{$param['end_time']} +1 day"))];
  138. }
  139. if ($param['apply_status'] != '') {
  140. $where[] = ['=', 'a.status', $param['apply_status']];
  141. }
  142. $select=[
  143. 'b.nickname as apply_user_name',
  144. 'b.phone as apply_user_phone',
  145. 'a.apply_money',
  146. 'b.openid open_id',
  147. 'b.wx_openid',
  148. '(select "微信") as apply_style_des',
  149. 'a.status as apply_status_id',
  150. new Expression("CASE a.status
  151. WHEN 1 THEN '待处理'
  152. WHEN 2 THEN '已审核'
  153. ELSE ''
  154. END
  155. as apply_status_des
  156. "),
  157. 'a.create_time apply_create_time',
  158. 'a.id as apply_id'
  159. ];
  160. $offset = ($param['current_page'] - 1) * $param['page_size'];
  161. $result=self::find()->select($select)
  162. ->from(self::tableName().' as a')
  163. ->leftJoin('fx_user as b','a.fx_uid=b.uid')
  164. ->where($where)
  165. ->orderBy('a.create_time desc')
  166. ->offset($offset)
  167. ->limit($param['page_size'])
  168. ->asArray()
  169. ->all();
  170. $count=self::find()->select('count(1) as count')->from(self::tableName().' as a')->leftJoin('fx_user as b','a.fx_uid=b.uid')->where($where)->asArray()->one();
  171. $count=$count['count'] ;
  172. return ['list'=>$result,'count'=>$count];
  173. }
  174. /*
  175. * 提现通过,状态变更
  176. */
  177. public function applyChange($apply_id){
  178. $count = self::updateAll(['status'=>2,'update_user'=>AdminUtil::$uid,'auth_time'=>date('Y-m-d H:i:s')], ['and', ['=', 'status', 1], ['=', 'id', $apply_id]]);
  179. return $count;
  180. }
  181. }