UserStoreController.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\system\StoreBill;
  4. use app\admin\model\system\StoreExtract;
  5. use app\admin\model\system\SystemStore;
  6. use app\models\user\User;
  7. use app\Request;
  8. use crmeb\services\FormBuilder as Form;
  9. use crmeb\services\JsonService as Json;
  10. use crmeb\services\UtilService;
  11. use crmeb\services\UtilService as Util;
  12. use think\facade\Route as Url;
  13. class UserStoreController
  14. {
  15. /**
  16. * 显示资金记录
  17. */
  18. public function index(Request $request)
  19. {
  20. $user = $request->user();
  21. if (!$user['user_store_id']) return app('json')->fail('非商家身份');
  22. $where['store_id'] = $user['user_store_id'];
  23. $list = StoreBill::where($where)
  24. ->field(['title', 'type'])
  25. ->group('type')
  26. ->distinct(true)
  27. ->select()
  28. ->toArray();
  29. $balance = SystemStore::where('id', $user['user_store_id'])->value('money');
  30. return app('json')->successful('ok', compact('list', 'balance'));
  31. }
  32. /**
  33. * 显示资金记录ajax列表
  34. */
  35. public function billlist(Request $request)
  36. {
  37. $user = $request->user();
  38. if (!$user['user_store_id']) return app('json')->fail('非商家身份');
  39. $where = Util::getMore([
  40. ['start_time', ''],
  41. ['end_time', ''],
  42. ['nickname', ''],
  43. ['limit', 20],
  44. ['page', 1],
  45. ['type', ''],
  46. ], $request);
  47. $where['store_id'] = $user['user_store_id'];
  48. return app('json')->successful('ok', StoreBill::getBillList($where));
  49. }
  50. /**
  51. * 添加/修改
  52. * @param int $id
  53. */
  54. public function saveExtract(Request $request)
  55. {
  56. $user = $request->user();
  57. if (!$user['user_store_id']) return app('json')->fail('非商家身份');
  58. $store_info = SystemStore::where('id', $user['user_store_id'])->find();
  59. if (!$store_info) return app('json')->fail('门店不存在');
  60. $uid = User::where('user_store_id', $store_info['id'])->column('uid');
  61. if (!count($uid)) return app('json')->fail('推荐用户不足100人');
  62. $count = User::where('spread_uid', 'in', $uid)->count();
  63. if ($count < 100) return app('json')->fail('推荐用户不足100人');
  64. $data = UtilService::postMore([
  65. ['alipay_code', ''],
  66. ['extract_type', ''],
  67. ['money', 0],
  68. ['name', ''],
  69. ['bankname', ''],
  70. ['cardnum', ''],
  71. ['weixin', ''],
  72. ], $request);
  73. if ($data['money'] > $store_info['money']) Json::fail('可提余额不足');
  74. if (!$data['cardnum'] == '')
  75. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $data['cardnum']))
  76. return app('json')->fail('银行卡号输入有误');
  77. if (StoreExtract::userExtract($store_info, $data))
  78. return app('json')->success('申请提现成功!');
  79. else
  80. return app('json')->fail(StoreExtract::getErrorInfo('提现失败'));
  81. }
  82. }