GzcLogs.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. $cardType = Db::name('user_certification')->where('uid',$log['uid'])->value('card_type');
  86. $gender = Db::name('user_certification')->where('uid',$log['uid'])->value('gender');
  87. $birthday = Db::name('user_certification')->where('uid',$log['uid'])->value('birthday');
  88. if(!$mobile || !$user_name || !$user_card || !$card_positive || !$card_reverse){
  89. return app('json')->fail('存在实名数据缺失');
  90. }
  91. //发起入账gzc
  92. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  93. $register = $OrderGzcRepository->register($mobile);
  94. if($register['status'] != 200) return app('json')->fail('入账失败:'.$register['message']);
  95. $uid = $register['data']['uid'] ?? 0;
  96. if(!$uid) return app('json')->fail('创建或获取用户失败');
  97. // 兼容港澳台用户认证
  98. $certification = $OrderGzcRepository->certification($uid, $mobile, $user_name, $user_card, $card_positive, $card_reverse,$cardType,$birthday,$gender);
  99. Log::info('pcpc认证结果' . json_encode($certification));
  100. if($certification['status'] != 200) return app('json')->fail('实名认证失败:'.$certification['message']);
  101. $gzc = $OrderGzcRepository->gzc($uid,$log['pension']);
  102. if($gzc['status'] != 200) return app('json')->fail('入账失败:'.$gzc['message']);
  103. $gzc_deposit_no = $gzc['data'];
  104. $gzc_confirm_result = $gzc['message'];
  105. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  106. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  107. Db::table('rrx_gzc_logs')
  108. ->where('id', $id)
  109. ->where('gzc', 0)
  110. ->where('success', 0)
  111. ->where('pension', '>', 0)
  112. ->update([
  113. 'gzc' => 1,
  114. 'platform_no' => $orderId,
  115. 'gzc_deposit_no' => $gzc_deposit_no,
  116. 'gzc_confirm_result' => $gzc_confirm_result,
  117. 'success' => 1,
  118. 'update_time' => date('Y-m-d H:i:s')
  119. ]);
  120. //发起成功更新记录值
  121. $order_id = Db::name('store_order')->where('order_sn', $log['out_trade_no'])->value('order_id');
  122. if($order_id){
  123. $bill = Db::name('user_bill')->where('link_id', $order_id)->where('commission_type', 5)->where('is_gzc', 'in', [0, 1])->find();
  124. if($bill){
  125. Db::name('user_bill')
  126. ->where('bill_id', $bill['bill_id'])
  127. ->update([
  128. 'is_gzc' => 2
  129. ]);
  130. }
  131. }
  132. return app('json')->success('发起成功', $log);
  133. }
  134. /**
  135. * 发起入账
  136. * author: php迷途小书童
  137. * created: 2021/3/24 13:56
  138. */
  139. public function inGzcAll()
  140. {
  141. $ids = $this->request->param('ids');
  142. if(!$ids) return app('json')->fail('请选择需要入账的记录');
  143. $ids = explode(",", $ids);
  144. if(!count($ids)){
  145. return app('json')->fail('暂无记录');
  146. }
  147. $cursor = Db::table('rrx_gzc_logs')
  148. ->whereIn('id', $ids)
  149. ->where('gzc', 0)
  150. ->where('success', 0)
  151. ->where('pension', '>', 0)
  152. ->cursor();
  153. foreach($cursor as $log){
  154. if (!$log){
  155. return app('json')->fail('暂无记录');
  156. }
  157. $mobile= $log['mobile'];
  158. $user_name = Db::name('user_certification')->where('uid',$log['uid'])->value('user_name');
  159. $user_card = Db::name('user_certification')->where('uid',$log['uid'])->value('user_card');
  160. $card_positive = Db::name('user_certification')->where('uid',$log['uid'])->value('card_positive');
  161. $card_reverse = Db::name('user_certification')->where('uid',$log['uid'])->value('card_reverse');
  162. $cardType = Db::name('user_certification')->where('uid',$log['uid'])->value('card_type');
  163. $gender = Db::name('user_certification')->where('uid',$log['uid'])->value('gender');
  164. $birthday = Db::name('user_certification')->where('uid',$log['uid'])->value('birthday');
  165. if(!$mobile || !$user_name || !$user_card || !$card_positive || !$card_reverse){
  166. return app('json')->fail('存在实名数据缺失');
  167. }
  168. //发起入账gzc
  169. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  170. $register = $OrderGzcRepository->register($mobile);
  171. if($register['status'] != 200) return app('json')->fail('入账失败:'.$register['message']);
  172. $uid = $register['data']['uid'] ?? 0;
  173. if(!$uid) return app('json')->fail('创建或获取用户失败');
  174. // 兼容港澳台用户认证
  175. $certification = $OrderGzcRepository->certification($uid, $mobile, $user_name, $user_card, $card_positive, $card_reverse,$cardType,$birthday,$gender);
  176. Log::info('pcpc认证结果' . json_encode($certification));
  177. if($certification['status'] != 200) return app('json')->fail('实名认证失败:'.$certification['message']);
  178. $gzc = $OrderGzcRepository->gzc($uid,$log['pension']);
  179. if($gzc['status'] != 200) return app('json')->fail('入账失败:'.$gzc['message']);
  180. $gzc_deposit_no = $gzc['data'];
  181. $gzc_confirm_result = $gzc['message'];
  182. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  183. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  184. Db::table('rrx_gzc_logs')
  185. ->where('id', $log['id'])
  186. ->where('gzc', 0)
  187. ->where('success', 0)
  188. ->where('pension', '>', 0)
  189. ->update([
  190. 'gzc' => 1,
  191. 'platform_no' => $orderId,
  192. 'gzc_deposit_no' => $gzc_deposit_no,
  193. 'gzc_confirm_result' => $gzc_confirm_result,
  194. 'success' => 1,
  195. 'update_time' => date('Y-m-d H:i:s')
  196. ]);
  197. //发起成功更新记录值
  198. $order_id = Db::name('store_order')->where('order_sn', $log['out_trade_no'])->value('order_id');
  199. if($order_id){
  200. $bill = Db::name('user_bill')->where('link_id', $order_id)->where('commission_type', 5)->where('is_gzc', 'in', [0, 1])->find();
  201. if($bill){
  202. Db::name('user_bill')
  203. ->where('bill_id', $bill['bill_id'])
  204. ->update([
  205. 'is_gzc' => 2
  206. ]);
  207. }
  208. }
  209. }
  210. return app('json')->success('发起成功');
  211. }
  212. /**
  213. * TODO 导出文件
  214. * @author Qinii
  215. * @day 2020-07-30
  216. */
  217. public function excel()
  218. {
  219. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn']);
  220. app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'order',0);
  221. return app('json')->success('开始导出数据');
  222. }
  223. public function checkAmount(){
  224. $where = $this->request->params(['user_name', 'user_card']);
  225. $return = $this->repository->checkAmount($where);
  226. return app('json')->success($return);
  227. }
  228. }