GzcLogs.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-15
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\system\merchant;
  11. use app\common\repositories\merchant\order\OrderGzcRepository;
  12. use app\common\repositories\merchant\order\OrderMerchantRepository;
  13. use crmeb\basic\BaseController;
  14. use app\common\repositories\store\ExcelRepository;
  15. use think\App;
  16. use think\facade\Db;
  17. use think\facade\Log;
  18. class GzcLogs extends BaseController
  19. {
  20. protected $repository;
  21. public function __construct(App $app, OrderGzcRepository $repository)
  22. {
  23. parent::__construct($app);
  24. $this->repository = $repository;
  25. }
  26. public function lst()
  27. {
  28. [$page, $limit] = $this->getPage();
  29. $where = $this->request->params(['keyword', 'date', 'status', 'account']);
  30. return app('json')->success($this->repository->getList($where, $page, $limit));
  31. }
  32. /**
  33. * 入账表单
  34. * author: php迷途小书童
  35. * created: 2021/3/24 13:56
  36. */
  37. public function inForm()
  38. {
  39. return app('json')->success(formToData($this->repository->inForm()));
  40. }
  41. /**
  42. * 编辑表单
  43. * @param $id
  44. * author: php迷途小书童
  45. * created: 2021/3/24 15:21
  46. */
  47. public function editForm($id)
  48. {
  49. return app('json')->success(formToData($this->repository->editForm($id)));
  50. }
  51. /**
  52. * 编辑处理
  53. * author: php迷途小书童
  54. * created: 2021/3/24 15:22
  55. */
  56. public function editFormPost()
  57. {
  58. $params = $this->request->params(['id', 'user_name', 'mobile', 'user_card', 'bank_name', 'branch_name', 'bank_account', 'bank_no', 'alipay_account','alipay_no','wxpay_account','wxpay_no','deposit_dt']);
  59. Db::table('rrx_gzc_logs')
  60. ->update($params);
  61. return app('json')->success('编辑成功');
  62. }
  63. /**
  64. * 发起入账
  65. * author: php迷途小书童
  66. * created: 2021/3/24 13:56
  67. */
  68. public function inGzc()
  69. {
  70. $id = intval($this->request->param('id'));
  71. $log = Db::table('rrx_gzc_logs')
  72. ->where('id', $id)
  73. ->where('gzc', 0)
  74. ->where('success', 0)
  75. ->where('pension', '>', 0)
  76. ->find();
  77. if(!$log){
  78. return app('json')->fail('请选择未入账的记录', );
  79. }
  80. $mobile= $log['mobile'];
  81. $user_name = Db::name('user_certification')->where('uid',$log['uid'])->value('user_name');
  82. $user_card = Db::name('user_certification')->where('uid',$log['uid'])->value('user_card');
  83. $card_positive = Db::name('user_certification')->where('uid',$log['uid'])->value('card_positive');
  84. $card_reverse = Db::name('user_certification')->where('uid',$log['uid'])->value('card_reverse');
  85. if(!$mobile || !$user_name || !$user_card || !$card_positive || !$card_reverse){
  86. return app('json')->fail('存在实名数据缺失');
  87. }
  88. //发起入账gzc
  89. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  90. $register = $OrderGzcRepository->register($mobile);
  91. if($register['status'] != 200) return app('json')->fail('入账失败:'.$register['message']);
  92. $uid = $register['data']['uid'] ?? 0;
  93. if(!$uid) return app('json')->fail('创建或获取用户失败');
  94. $certification = $OrderGzcRepository->certification($uid, $mobile, $user_name, $user_card, $card_positive, $card_reverse);
  95. if($certification['status'] != 200) return app('json')->fail('实名认证失败:'.$certification['message']);
  96. $gzc = $OrderGzcRepository->gzc($uid,$log['pension']);
  97. if($gzc['status'] != 200) return app('json')->fail('入账失败:'.$gzc['message']);
  98. $gzc_deposit_no = $gzc['data'];
  99. $gzc_confirm_result = $gzc['message'];
  100. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  101. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  102. Db::table('rrx_gzc_logs')
  103. ->where('id', $id)
  104. ->where('gzc', 0)
  105. ->where('success', 0)
  106. ->where('pension', '>', 0)
  107. ->update([
  108. 'gzc' => 1,
  109. 'platform_no' => $orderId,
  110. 'gzc_deposit_no' => $gzc_deposit_no,
  111. 'gzc_confirm_result' => $gzc_confirm_result,
  112. 'success' => 1,
  113. 'update_time' => date('Y-m-d H:i:s')
  114. ]);
  115. //发起成功更新记录值
  116. $order_id = Db::name('store_order')->where('order_sn', $log['out_trade_no'])->value('order_id');
  117. if($order_id){
  118. $bill = Db::name('user_bill')->where('link_id', $order_id)->where('commission_type', 5)->where('is_gzc', 'in', [0, 1])->find();
  119. if($bill){
  120. Db::name('user_bill')
  121. ->where('bill_id', $bill['bill_id'])
  122. ->update([
  123. 'is_gzc' => 2
  124. ]);
  125. }
  126. }
  127. return app('json')->success('发起成功', $log);
  128. }
  129. /**
  130. * 发起入账
  131. * author: php迷途小书童
  132. * created: 2021/3/24 13:56
  133. */
  134. public function inGzcAll()
  135. {
  136. $ids = $this->request->param('ids');
  137. if(!$ids) return app('json')->fail('请选择需要入账的记录');
  138. $ids = explode(",", $ids);
  139. if(!count($ids)){
  140. return app('json')->fail('暂无记录');
  141. }
  142. $cursor = Db::table('rrx_gzc_logs')
  143. ->whereIn('id', $ids)
  144. ->where('gzc', 0)
  145. ->where('success', 0)
  146. ->where('pension', '>', 0)
  147. ->cursor();
  148. foreach($cursor as $log){
  149. if (!$log){
  150. return app('json')->fail('暂无记录');
  151. }
  152. $mobile= $log['mobile'];
  153. $user_name = Db::name('user_certification')->where('uid',$log['uid'])->value('user_name');
  154. $user_card = Db::name('user_certification')->where('uid',$log['uid'])->value('user_card');
  155. $card_positive = Db::name('user_certification')->where('uid',$log['uid'])->value('card_positive');
  156. $card_reverse = Db::name('user_certification')->where('uid',$log['uid'])->value('card_reverse');
  157. $cardType = Db::name('user_certification')->where('uid',$log['uid'])->value('card_type');
  158. $gender = Db::name('user_certification')->where('uid',$log['uid'])->value('gender');
  159. $birthday = Db::name('user_certification')->where('uid',$log['uid'])->value('birthday');
  160. if(!$mobile || !$user_name || !$user_card || !$card_positive || !$card_reverse){
  161. return app('json')->fail('存在实名数据缺失');
  162. }
  163. //发起入账gzc
  164. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  165. $register = $OrderGzcRepository->register($mobile);
  166. if($register['status'] != 200) return app('json')->fail('入账失败:'.$register['message']);
  167. $uid = $register['data']['uid'] ?? 0;
  168. if(!$uid) return app('json')->fail('创建或获取用户失败');
  169. // 兼容港澳台用户认证
  170. $certification = $OrderGzcRepository->certification($uid, $mobile, $user_name, $user_card, $card_positive, $card_reverse,$cardType,$birthday,$gender);
  171. Log::info('pcpc认证结果' . json_encode($certification));
  172. if($certification['status'] != 200) return app('json')->fail('实名认证失败:'.$certification['message']);
  173. $gzc = $OrderGzcRepository->gzc($uid,$log['pension']);
  174. if($gzc['status'] != 200) return app('json')->fail('入账失败:'.$gzc['message']);
  175. $gzc_deposit_no = $gzc['data'];
  176. $gzc_confirm_result = $gzc['message'];
  177. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  178. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  179. Db::table('rrx_gzc_logs')
  180. ->where('id', $log['id'])
  181. ->where('gzc', 0)
  182. ->where('success', 0)
  183. ->where('pension', '>', 0)
  184. ->update([
  185. 'gzc' => 1,
  186. 'platform_no' => $orderId,
  187. 'gzc_deposit_no' => $gzc_deposit_no,
  188. 'gzc_confirm_result' => $gzc_confirm_result,
  189. 'success' => 1,
  190. 'update_time' => date('Y-m-d H:i:s')
  191. ]);
  192. //发起成功更新记录值
  193. $order_id = Db::name('store_order')->where('order_sn', $log['out_trade_no'])->value('order_id');
  194. if($order_id){
  195. $bill = Db::name('user_bill')->where('link_id', $order_id)->where('commission_type', 5)->where('is_gzc', 'in', [0, 1])->find();
  196. if($bill){
  197. Db::name('user_bill')
  198. ->where('bill_id', $bill['bill_id'])
  199. ->update([
  200. 'is_gzc' => 2
  201. ]);
  202. }
  203. }
  204. }
  205. return app('json')->success('发起成功');
  206. }
  207. /**
  208. * TODO 导出文件
  209. * @author Qinii
  210. * @day 2020-07-30
  211. */
  212. public function excel()
  213. {
  214. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn']);
  215. app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'order',0);
  216. return app('json')->success('开始导出数据');
  217. }
  218. public function checkAmount(){
  219. $where = $this->request->params(['user_name', 'user_card']);
  220. $return = $this->repository->checkAmount($where);
  221. return app('json')->success($return);
  222. }
  223. }