UserExtract.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-16
  7. *
  8. *
  9. */
  10. namespace app\controller\merchant\user;
  11. use app\common\repositories\store\ExcelRepository;
  12. use app\common\repositories\user\UserExtractRepository;
  13. use crmeb\basic\BaseController;
  14. use crmeb\services\ExcelService;
  15. use crmeb\services\SpreadsheetExcelService;
  16. use think\App;
  17. use app\common\repositories\user\UserExtractRepository as repository;
  18. use think\facade\Cache;
  19. use think\facade\Db;
  20. class UserExtract extends BaseController
  21. {
  22. /**
  23. * @var repository
  24. */
  25. public $repository;
  26. //服务手续费
  27. private $service_money_ratio = 0.06;
  28. /**
  29. * UserExtract constructor.
  30. * @param App $app
  31. * @param repository $repository
  32. */
  33. public function __construct(App $app,repository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. }
  38. /**
  39. * TODO
  40. * @return mixed
  41. * @author Qinii
  42. * @day 2020-06-16
  43. */
  44. public function lst()
  45. {
  46. [$page,$limit] = $this->getPage();
  47. $where = $this->request->params(['status','keyword','date','extract_type','uid']);
  48. $where['mer_id']=$this->request->merId();
  49. $res = $this->repository->serach($where,$page,$limit);
  50. foreach ($res['list'] as $k=>$v){
  51. $res['list'][$k]['certification']= Db::name('user_certification')->where('uid', $v['uid'])->find();;
  52. $res['list'][$k]['bank_info_data']=[];
  53. $pay_info='';
  54. if($v['bank_info']!=''){
  55. $res['list'][$k]['bank_info_data']=json_decode($v['bank_info'],true);
  56. $pay_info=$res['list'][$k]['certification']['user_name'].' ';
  57. $pay_info.=$res['list'][$k]['certification']['user_card']." ";
  58. $pay_info.=$res['list'][$k]['bank_info_data']['bank_name'].' ';
  59. $pay_info.=$res['list'][$k]['bank_info_data']['bank_open_name'].' ';
  60. $pay_info.=$res['list'][$k]['bank_code'];
  61. }
  62. $res['list'][$k]['status_name']='';
  63. if($v['status']=='0') $res['list'][$k]['status_name']='审核中';
  64. if($v['status']=='1') $res['list'][$k]['status_name']='已打款';
  65. if($v['status']=='-1') $res['list'][$k]['status_name']='已拒绝';
  66. if($v['extract_type']=='3') $res['list'][$k]['extract_type_name']='银行卡';
  67. if($v['status']=='0') $res['list'][$k]['status_time']='';
  68. $res['list'][$k]['extract_price']=set_price_rtrim($v['extract_price']);
  69. $res['list'][$k]['service_money']=set_price_rtrim( $v['service_money']);
  70. $res['list'][$k]['money']=set_price_rtrim($v['extract_price'] - $v['service_money']);
  71. $res['list'][$k]['pay_info']=$pay_info;
  72. if($v['extract_type']=='4'){
  73. $res['list'][$k]['status_name']='已完成';
  74. $res['list'][$k]['pay_info']='人工减少-'.$v['mark'];
  75. }
  76. if(!$v['fail_msg'] || $v['fail_msg']==''){
  77. $res['list'][$k]['fail_msg']='--';
  78. }
  79. if(!$v['status_time'] || $v['status_time']==''){
  80. $res['list'][$k]['status_time']='--';
  81. }
  82. // $res['list'][$k]['list']=$this->repository->get_user_extract_item($v['extract_id']);
  83. }
  84. //查询用户可提现金额
  85. $merid = $this->request->merId();
  86. $merchant= Db::name('merchant')->where('mer_id', $merid)->find();
  87. $res['brokerage_price'] = $merchant['brokerage_price'];
  88. return app('json')->success($res);
  89. }
  90. public function new_lst()
  91. {
  92. [$page,$limit] = $this->getPage();
  93. $where = $this->request->params(['status','keyword','date','extract_type','uid']);
  94. $res = $this->repository->new_search($where,$page,$limit);
  95. foreach ($res['list'] as $k=>$v){
  96. $res['list'][$k]['certification']= Db::name('user_certification')->where('uid', $v['uid'])->find();;
  97. $res['list'][$k]['bank_info_data']=[];
  98. $pay_info='';
  99. if($v['bank_info']!=''){
  100. $res['list'][$k]['bank_info_data']=json_decode($v['bank_info'],true);
  101. $pay_info=$res['list'][$k]['certification']['user_name'].' ';
  102. $pay_info.=$res['list'][$k]['certification']['user_card']." ";
  103. $pay_info.=$res['list'][$k]['bank_info_data']['bank_name'].' ';
  104. $pay_info.=$res['list'][$k]['bank_info_data']['bank_open_name'].' ';
  105. $pay_info.=$res['list'][$k]['bank_code'];
  106. }
  107. $res['list'][$k]['status_name']='';
  108. if($v['status']=='0') $res['list'][$k]['status_name']='审核中';
  109. if($v['status']=='1') $res['list'][$k]['status_name']='已打款';
  110. if($v['status']=='-1') $res['list'][$k]['status_name']='已拒绝';
  111. if($v['extract_type']=='3') $res['list'][$k]['extract_type_name']='银行卡';
  112. if($v['status']=='0') $res['list'][$k]['status_time']='';
  113. $res['list'][$k]['extract_price']=set_price_rtrim($v['extract_price']);
  114. $res['list'][$k]['service_money']=set_price_rtrim( $v['service_money']);
  115. $res['list'][$k]['money']=set_price_rtrim($v['extract_price'] - $v['service_money']);
  116. $res['list'][$k]['pay_info']=$pay_info;
  117. if($v['extract_type']=='4'){
  118. $res['list'][$k]['status_name']='已完成';
  119. $res['list'][$k]['pay_info']='人工减少-'.$v['mark'];
  120. }
  121. if(!$v['fail_msg'] || $v['fail_msg']==''){
  122. $res['list'][$k]['fail_msg']='--';
  123. }
  124. if(!$v['status_time'] || $v['status_time']==''){
  125. $res['list'][$k]['status_time']='--';
  126. }
  127. // $res['list'][$k]['list']=$this->repository->get_user_extract_item($v['extract_id']);
  128. }
  129. //查询用户可提现金额
  130. $merid = $this->request->merId();
  131. $merchant= Db::name('merchant')->where('mer_id', $merid)->find();
  132. $user = Db::name('user')->where('uid', $merchant['uid'])->find();
  133. $res['brokerage_price'] = $user['brokerage_price'];
  134. return app('json')->success($res);
  135. }
  136. /**
  137. * TODO 导出文件
  138. * @author Qinii
  139. * @day 2020-07-30
  140. */
  141. public function excel()
  142. {
  143. $where = $this->request->params(['status','keyword','date','extract_type']);
  144. $where['mer_id']=$this->request->merId();
  145. $res = $this->repository->serach($where,1,100000);
  146. $arr=[];
  147. foreach ($res['list'] as $k=>$v){
  148. $res['list'][$k]['bank_info_data']=[];
  149. $bane_name='';
  150. if($v['bank_info']!=''){
  151. $res['list'][$k]['bank_info_data']=json_decode($v['bank_info'],true);
  152. $bane_name=$res['list'][$k]['bank_info_data']['bank_name'];
  153. }
  154. $certification= Db::name('user_certification')->where('uid', $v['uid'])->find();;
  155. $v['extract_type_name']='';
  156. $v['status_name']='';
  157. if($v['extract_type']==1) $v['extract_type_name']='微信';
  158. if($v['extract_type']==2) $v['extract_type_name']='支付宝';
  159. if($v['extract_type']==3) $v['extract_type_name']='银行卡';
  160. if($v['status']==-1) $v['status_name']='未通过';
  161. if($v['status']=='0') $v['status_name']='审核中';
  162. if($v['status']=='1') $v['status_name']='已提现';
  163. $arr[]=array(
  164. $v['create_time'],
  165. $certification['user_name'],
  166. $v['extract_price'],
  167. $v['service_money'],
  168. ($v['extract_price'] - $v['service_money']),
  169. $v['extract_type_name'],
  170. $bane_name,
  171. $v['bank_address'],
  172. ' '.$v['bank_code'],
  173. $v['status_name'],
  174. );
  175. }
  176. $header = [
  177. '申请时间','姓名','申请金额','综合服务费','实际到账金额','提现方式','所属银行','所属银行支行','银行卡号','状态'
  178. ];
  179. $filename = '提现列表_'.date('YmdHis').'_'.rand(10000,99999);
  180. $title = '提现列表';
  181. $name = '提现信息';
  182. $info = '生成时间:' . date('Y-m-d H:i:s',time());
  183. $suffix='xlsx';
  184. $path='extract';
  185. unset($_instance);
  186. $_instance = SpreadsheetExcelService::instance_xin();
  187. $_path =$_instance
  188. ->createOrActive()
  189. ->setExcelHeader($header)
  190. ->setExcelTile($title, $name, $info)
  191. ->setExcelContent($arr)
  192. ->excelSave($filename, $suffix, $path);
  193. $data= [
  194. 'name' => $filename.'.'.$suffix,
  195. 'status' => 1,
  196. 'path' => '/'.$_path
  197. ];
  198. return app('json')->success('ok',$data);
  199. }
  200. /**
  201. * TODO
  202. * @param $id
  203. * @return mixed
  204. * @author Qinii
  205. * @day 2020-06-16
  206. */
  207. public function switchStatus($id)
  208. {
  209. $data = $this->request->params(['status','fail_msg','mark']);
  210. if($data['status'] == '-1' && empty($data['fail_msg']))
  211. return app('json')->fail('请填写拒绝原因');
  212. if(!$this->repository->getWhereCount($id))
  213. return app('json')->fail('数据不存在或状态错误');
  214. $data['admin_id'] = $this->request->adminId();
  215. $data['status_time'] = date('Y-m-d H:i:s',time());
  216. $extract_data=Db::name('user_extract')->where('extract_id',$id)->find();
  217. if($data['status']!='-1'){
  218. if($extract_data['extract_type']==1){
  219. return app('json')->success('微信不能提现');
  220. // $res=$this->repository->WechatTransfers($id);
  221. // if($res['code']==201){
  222. // return app('json')->success('微信处理中,请稍后');
  223. // }
  224. // }elseif ($extract_data['extract_type']==2){
  225. // $res=$this->repository->AliTransfers($id);
  226. }elseif ($extract_data['extract_type']==3){
  227. $res= ['code'=>200,'msg'=>'成功'];
  228. }
  229. if($res['code']!=200 && $extract_data['types']==1){
  230. Db::name('user_rich')->where('uid',$extract_data['uid'])->inc('red', $extract_data['extract_price'])->update();
  231. Db::name('user_rich_log')->insert([
  232. 'uid' => $extract_data['uid'],
  233. 'red' => $extract_data['extract_price'],
  234. 'pm' => 1,
  235. 'time' => time(),
  236. 'order_id' => 0,
  237. 'mark' => '提现失败返还红积分'
  238. ]);
  239. return app('json')->fail(isset($res['msg'])?$res['msg']:'提现失败',$res);
  240. }
  241. }else{
  242. if($extract_data['withdrawal_type']==2) {
  243. Db::name('entropy_barter_bill')->where('order_no', $extract_data['order_sn'])->where('pm', 2)->update(['status' => 3, 'remarks' => '审核已拒绝']);
  244. $eb_bill = Db::name('entropy_barter_bill')->where('order_no', $extract_data['order_sn'])->where('pm', 2)->find();
  245. Db::name('entropy_barter_user_' . $extract_data['mer_id'])->where('eb_id', $eb_bill['to_id'])->inc('wallet', $extract_data['extract_price'])->update();
  246. }
  247. }
  248. if($extract_data['withdrawal_type']==1){
  249. $this->repository->switchStatus($id,$data);
  250. }else if($extract_data['withdrawal_type']==3){
  251. if($data['status'] == '-1'){
  252. $where['uid'] = $extract_data['uid'];
  253. $where['mer_id'] = $extract_data['mer_id'];
  254. Db::name('enterprise_user')->where($where)->inc('commission', $extract_data['extract_price'])->update();
  255. }
  256. Db::name('user_extract')->where('extract_id',$id)->update($data);
  257. }else{
  258. Db::name('user_extract')->where('extract_id',$id)->update($data);
  259. }
  260. return app('json')->success('审核成功');
  261. }
  262. public function create()
  263. {
  264. $data = $this->request->params(['extract_price']);
  265. $extract_price = $data['extract_price'] ?? 0;
  266. //查询用户可提现金额
  267. $merid = $this->request->merId();
  268. $merchant= Db::name('merchant')->where('mer_id', $merid)->find();
  269. $user = Db::name('user')->where('uid', $merchant['uid'])->find();
  270. if ($extract_price > $merchant['brokerage_price']) {
  271. return app('json')->fail('输入金额超出可提现金额~');
  272. }
  273. if ($extract_price < 100) {
  274. return app('json')->fail('最低提现金额为100~');
  275. }
  276. if ($extract_price % 100 != 0) {
  277. return app('json')->fail('提现金额应为100的倍数~');
  278. }
  279. //创建提现记录
  280. $extract = $this->repository->create_yhc($user, $merchant, [
  281. 'extract_type' => 3,
  282. 'extract_price' => $extract_price,
  283. 'service_money' => $extract_price * $this->service_money_ratio,//综合服务费6%
  284. ]);
  285. return \app('json')->success($extract);
  286. }
  287. public function service_money()
  288. {
  289. $data = $this->request->params(['extract_price']);
  290. $extract_price = intval($data['extract_price']) ?? 0;
  291. $res = [
  292. 'extract_price' => $extract_price,
  293. 'service_money' => $extract_price * $this->service_money_ratio,//综合服务费6%
  294. ];
  295. $res['deserve_money'] = $res['extract_price'] - $res['service_money'];
  296. return \app('json')->success($res);
  297. }
  298. }