User.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. namespace app\data\controller\api\business;
  3. use app\data\model\ShopFeedback;
  4. use app\data\model\SystemUserAmount;
  5. use app\data\model\SystemUserBank;
  6. use app\data\model\SystemUserWithdrawal;
  7. use think\admin\Controller;
  8. use hg\apidoc\annotation\Title;
  9. use hg\apidoc\annotation\Method;
  10. use hg\apidoc\annotation\Param;
  11. use hg\apidoc\annotation\Returned;
  12. use think\admin\model\SystemUser;
  13. /**
  14. * 商家个人中心
  15. */
  16. class User extends Controller
  17. {
  18. /**
  19. * 控制器初始化
  20. */
  21. protected function initialize()
  22. {
  23. $purchase_model = new Common($this->app);
  24. $user = $purchase_model->uuid();
  25. $this->user = $user;
  26. }
  27. /**
  28. * @Title ("用户信息")
  29. * @Method ("get")
  30. * @return void
  31. */
  32. public function user_info(){
  33. $user_info = $this->user;
  34. $this->success('用户信息',$user_info);
  35. }
  36. /**
  37. * @Title ("意见反馈")
  38. * @Method ("post")
  39. * @Param ("title",desc="反馈标题")
  40. * @Param ("content",desc="反馈内容")
  41. * @Param ("image",desc="图片")
  42. * @return void
  43. */
  44. public function feedback(){
  45. $data = $this->_vali([
  46. 'title.require'=>'反馈标题不能为空',
  47. 'content.require'=>'反馈内容不能为空',
  48. 'image.default'=>''
  49. ]);
  50. $feedback_data= [
  51. 'admin_id'=>$this->user->id,
  52. 'title'=>$data['title'],
  53. 'content'=>$data['content'],
  54. 'image'=>$data['image'],
  55. 'status'=>1,
  56. 'create_time'=>date('Y-m-d H:i:s')
  57. ];
  58. ShopFeedback::mk()->insert($feedback_data);
  59. $this->success('意见反馈已提交');
  60. }
  61. /**
  62. * @Title ("反馈意见列表")
  63. * @Method ("get")
  64. * @return void
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\DbException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. */
  69. public function feedback_list(){
  70. $admin_id = $this->user->id;
  71. $list = ShopFeedback::mk()->where('admin_id',$admin_id)->select();
  72. $this->success('反馈意见列表',$list);
  73. }
  74. /**
  75. * @Title ("删除意见")
  76. * @Method ("post")
  77. * @Param ("feedback_id",desc="删除意见数据id")
  78. * @return void
  79. */
  80. public function del_feedback(){
  81. $data = $this->_vali(
  82. [
  83. 'feedback_id.require'=>"参数不能为空",
  84. ]
  85. );
  86. $admin_id =$this->user->id;
  87. ShopFeedback::mk()->where('id',$data['feedback'])->where('admin_id',$admin_id)->delete();
  88. $this->success('反馈记录已删除');
  89. }
  90. /**
  91. * @Title ("编辑意见信息")
  92. * @Method ("post")
  93. * @Param ("feedback_id",desc="编辑意见数据id")
  94. * @Param ("title",desc="反馈标题")
  95. * @Param ("content",desc="反馈内容")
  96. * @Param ("image",desc="图片")
  97. * @return void
  98. */
  99. public function save_feedback(){
  100. $data = $this->_vali(
  101. [
  102. 'feedback_id.require'=>"参数不能为空",
  103. 'title.require'=>'反馈标题不能为空',
  104. 'content.require'=>'反馈内容不能为空',
  105. 'image.default'=>''
  106. ]
  107. );
  108. $feedback_data=[
  109. 'title'=>$data['title'],
  110. 'content'=>$data['content'],
  111. 'image'=>$data['image'],
  112. 'status'=>1,
  113. 'create_time'=>date('Y-m-d H:i:s')
  114. ];
  115. $admin_id =$this->user->id;
  116. ShopFeedback::mk()->where('id',$data['feedback'])->where('admin_id',$admin_id)->save($feedback_data);
  117. $this->success('反馈记录已删除');
  118. }
  119. /**
  120. * @Title ("添加用户银行卡")
  121. * @Method("post")
  122. * @Param ("bank",desc="银行名称")
  123. * @Param ("number",desc="银行卡号")
  124. * @Param ("address",desc="开户行")
  125. * @Param ("real_name",desc="持卡人真是姓名")
  126. * @return void
  127. */
  128. public function bank_add(){
  129. $admin_id = $this->user->id;
  130. $data = $this->_vali([
  131. 'bank.require'=>'银行名称不能空',
  132. 'number.require'=>'银行卡号不能为空',
  133. 'address.require'=>'开户行信息不能为空',
  134. 'real_name.require'=>'持卡人姓名不能为空'
  135. ]);
  136. $bank_data = [
  137. 'admin_id'=>$admin_id,
  138. 'bank'=>$data['bank'],
  139. 'number'=>$data['number'],
  140. 'address'=>$data['address'],
  141. 'real_name'=>$data['real_name']
  142. ];
  143. SystemUserBank::mk()->insertGetId($bank_data);
  144. $this->success('银行卡添加成功');
  145. }
  146. /**
  147. * @Title ("我的银行卡列表")
  148. * @Method ("get")
  149. * @return void
  150. * @throws \think\db\exception\DataNotFoundException
  151. * @throws \think\db\exception\DbException
  152. * @throws \think\db\exception\ModelNotFoundException
  153. */
  154. public function user_bank(){
  155. echo 222;die;
  156. $admin_id = $this->user->id;
  157. $query = SystemUserBank::mQuery();
  158. $list = $query->where('admin_id',$admin_id->id)->order('id desc')->page(true, false, false, 10);
  159. echo SystemUserBank::getLastSql();
  160. $this->success('银行卡列表',$list);
  161. }
  162. /**
  163. * @Title ("银行卡解绑")
  164. * @Method ("post")
  165. * @Param ("bank_id",desc="银行卡id")
  166. * @return void
  167. * @throws \think\db\exception\DataNotFoundException
  168. * @throws \think\db\exception\DbException
  169. * @throws \think\db\exception\ModelNotFoundException
  170. */
  171. public function bank_del(){
  172. $admin_id = $this->user->id;
  173. $data = $this->_vali(
  174. ['id.require'=>'请选择解绑银行']
  175. );
  176. $is_have = SystemUserBank::mk()->where(['admin_id'=>$admin_id,'id'=>$data])->find();
  177. if(empty($is_have)){
  178. $this->error('解绑信息错误');
  179. }
  180. SystemUserBank::mk()->where(['admin_id'=>$admin_id,'id'=>$data])->delete();
  181. $this->success('银行卡已解绑');
  182. }
  183. /**
  184. * @Title ("邮箱绑定")
  185. * @Method ("post")
  186. * @Param ("mailbox",desc="邮箱")
  187. * @return void
  188. */
  189. public function user_mailbox(){
  190. $admin_id = $this->user->id;
  191. $data = $this->_vali(
  192. ['mailbox.require'=>'邮箱不能为空!']
  193. );
  194. SystemUser::mk()->where('id',$admin_id)->save(['contact_mail'=>$data['mailbox']]);
  195. $this->success('邮箱绑定成功');
  196. }
  197. /**
  198. * @Title ("修改密码")
  199. * @Method ("post")
  200. * @Param ("old_password",desc="原始密码")
  201. * @Param ("new_password",desc="新密码")
  202. * @return void
  203. */
  204. public function user_password(){
  205. $admin_id= $this->user->id;
  206. $data = $this->_vali(
  207. [
  208. 'old_password.require'=>'原始密码不能为空',
  209. 'new_password.require'=>'新密码不能为空'
  210. ]
  211. );
  212. if($this->user->password!=md5($data['old_password'])){
  213. $this->error('原始密码不正确');
  214. }
  215. $token=rand('00000','99999');
  216. SystemUser::mk()->where('id',$admin_id)->save(['password'=>md5($data['new_password']),'token'=>$token]);
  217. $this->success('密码重置成功请重新登录!');
  218. }
  219. /**
  220. * @Title ("商家提现申请")
  221. * @Method ("post")
  222. * @Param ("bank_number",desc="提现卡号")
  223. * @Param ("money",desc="提现金额")
  224. * @return void
  225. * @throws \think\db\exception\DataNotFoundException
  226. * @throws \think\db\exception\DbException
  227. * @throws \think\db\exception\ModelNotFoundException
  228. */
  229. public function user_withdrawal(){
  230. $admin_id= $this->user->id;
  231. $data = $this->_vali(
  232. [
  233. 'bank_number.require'=>'提现卡号不能为空',
  234. 'money.require'=>'提现金额不能为空'
  235. ]
  236. );
  237. if($data['money']<1){
  238. $this->error('提现金额不能小于'.'1');
  239. }
  240. if($data['money']>$this->user->money){
  241. $this->error('余额不足');
  242. }
  243. $bank_info = SystemUserBank::mk()->where(['admin_id'=>$admin_id,'number'=>$data['bank_number']])->find();
  244. if($bank_info){
  245. $this->error('提现账号有问题');
  246. }
  247. $withdrawal_data = [
  248. 'admin_id'=>$admin_id,
  249. 'real_name'=>$data['real_name'],
  250. 'bank'=>$bank_info['bank'],
  251. 'number'=>$bank_info['number'],
  252. 'address'=>$bank_info['address'],
  253. 'money'=>$data['money'],
  254. 'before'=>$this->user->money,
  255. 'after'=>$this->user->money-$data['money'],
  256. 'charges'=>10,
  257. 'amount'=>$data['money']-10,
  258. 'create_time'=>date('Y-m-d H:i:s'),
  259. 'status'=>1
  260. ];
  261. SystemUserWithdrawal::mk()->insertGetId($withdrawal_data);
  262. $this->success('提现申请已提交,等待打款');
  263. }
  264. /**
  265. * @Title ("余额记录")
  266. * @Method ("get")
  267. * @return void
  268. */
  269. public function user_amount(){
  270. $admin_id = $this->user->id;
  271. $query = SystemUserAmount::mQuery();
  272. $list = $query->where('admin_id',$admin_id->id)->order('id desc')->page(true, false, false, 10);
  273. $this->success('余额记录明细',$list);
  274. }
  275. }