GzcLogs.php 10 KB

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