GzcLogs.php 9.0 KB

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