UserStoreController.php 3.3 KB

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