UserStoreController.php 3.2 KB

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