GzcLogs.php 10 KB

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