User.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\Goods;
  4. use app\common\controller\Api;
  5. use app\common\library\Ems;
  6. use app\common\library\Sms;
  7. use app\common\model\Order;
  8. use app\common\model\OrderInvoice;
  9. use fast\Random;
  10. use think\Config;
  11. use think\Db;
  12. use think\Exception;
  13. use think\Validate;
  14. /**
  15. * 会员接口
  16. */
  17. class User extends Api
  18. {
  19. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
  20. protected $noNeedRight = '*';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. if (!Config::get('fastadmin.usercenter')) {
  25. $this->error(__('User center already closed'));
  26. }
  27. }
  28. /**
  29. * 会员中心
  30. */
  31. public function index()
  32. {
  33. $this->auth->getUser()->head_img = config('site.head_img');
  34. $this->auth->getUser()->gw_name = config('site.gw_name');
  35. $this->auth->getUser()->dingding = config('site.dingding');
  36. $this->auth->getUser()->qywx = config('site.qywx');
  37. $this->success('', ['welcome' => $this->auth->getUser()]);
  38. }
  39. /**
  40. * 会员登录
  41. *
  42. * @ApiMethod (POST)
  43. * @param string $account 账号
  44. * @param string $password 密码
  45. */
  46. public function login()
  47. {
  48. $account = $this->request->post('account');
  49. $password = $this->request->post('password');
  50. if (!$account || !$password) {
  51. $this->error(__('Invalid parameters'));
  52. }
  53. $ret = $this->auth->login($account, $password);
  54. if ($ret) {
  55. $data = ['userinfo' => $this->auth->getUserinfo()];
  56. $this->success(__('Logged in successful'), $data);
  57. } else {
  58. $this->error($this->auth->getError());
  59. }
  60. }
  61. /**
  62. * 手机验证码登录
  63. *
  64. * @ApiMethod (POST)
  65. * @param string $mobile 手机号
  66. * @param string $captcha 验证码
  67. */
  68. public function mobilelogin()
  69. {
  70. $mobile = $this->request->post('mobile');
  71. $captcha = $this->request->post('captcha');
  72. // if (!$mobile || !$captcha) {
  73. // $this->error(__('Invalid parameters'));
  74. // }
  75. if (!Validate::regex($mobile, "^1\d{10}$")) {
  76. $this->error(__('Mobile is incorrect'));
  77. }
  78. // if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  79. // $this->error(__('Captcha is incorrect'));
  80. // }
  81. $user = \app\common\model\User::getByMobile($mobile);
  82. if ($user) {
  83. if ($user->status != 'normal') {
  84. $this->error(__('Account is locked'));
  85. }
  86. //如果已经有账号则直接登录
  87. $ret = $this->auth->direct($user->id);
  88. } else {
  89. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
  90. }
  91. if ($ret) {
  92. Sms::flush($mobile, 'mobilelogin');
  93. $data = ['userinfo' => $this->auth->getUserinfo()];
  94. $this->success(__('Logged in successful'), $data);
  95. } else {
  96. $this->error($this->auth->getError());
  97. }
  98. }
  99. /**
  100. * 注册会员
  101. *
  102. * @ApiMethod (POST)
  103. * @param string $username 用户名
  104. * @param string $password 密码
  105. * @param string $mobile 手机号
  106. * @param string $code 验证码
  107. */
  108. public function register()
  109. {
  110. $username = $this->request->post('username');
  111. $password = $this->request->post('password');
  112. // $email = $this->request->post('email');
  113. $mobile = $this->request->post('mobile');
  114. $code = $this->request->post('code');
  115. if (!$username) {
  116. $this->error(__('Invalid parameters'));
  117. }
  118. // if ($email && !Validate::is($email, "email")) {
  119. // $this->error(__('Email is incorrect'));
  120. // }
  121. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  122. $this->error(__('Mobile is incorrect'));
  123. }
  124. // $ret = Sms::check($mobile, $code, 'register');
  125. // if ($ret != 8888) {
  126. // $this->error(__('Captcha is incorrect'));
  127. // }
  128. $ret = $this->auth->register($username, $mobile, $password,[]);
  129. if ($ret) {
  130. $data = ['userinfo' => $this->auth->getUserinfo()];
  131. $this->success(__('Sign up successful'), $data);
  132. } else {
  133. $this->error($this->auth->getError());
  134. }
  135. }
  136. /**
  137. * 退出登录
  138. * @ApiMethod (POST)
  139. */
  140. public function logout()
  141. {
  142. if (!$this->request->isPost()) {
  143. $this->error(__('Invalid parameters'));
  144. }
  145. $this->auth->logout();
  146. $this->success(__('Logout successful'));
  147. }
  148. /**
  149. * 修改会员个人信息
  150. *
  151. * @ApiMethod (POST)
  152. * @param string $avatar 头像地址
  153. * @param string $username 用户名
  154. * @param string $nickname 昵称
  155. * @param string $bio 个人简介
  156. * @param string $company 公司
  157. * @param string $company_site 公司地址
  158. */
  159. public function profile()
  160. {
  161. $user = $this->auth->getUser();
  162. $username = $this->request->post('username');
  163. $nickname = $this->request->post('nickname');
  164. $bio = $this->request->post('bio');
  165. $company = $this->request->post('company');
  166. $company_site = $this->request->post('company_site');
  167. $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
  168. if($avatar){
  169. $user->avatar = $avatar;
  170. }
  171. if ($username) {
  172. $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
  173. if ($exists) {
  174. $this->error(__('Username already exists'));
  175. }
  176. $user->username = $username;
  177. }
  178. if ($nickname) {
  179. $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
  180. if ($exists) {
  181. $this->error(__('Nickname already exists'));
  182. }
  183. $user->nickname = $nickname;
  184. }
  185. $user->bio = $bio;
  186. $user->company = $company;
  187. $user->company_site = $company_site;
  188. $user->save();
  189. $this->success();
  190. }
  191. /**
  192. * 修改邮箱
  193. *
  194. * @ApiMethod (POST)
  195. * @param string $email 邮箱
  196. * @param string $captcha 验证码
  197. */
  198. public function changeemail()
  199. {
  200. $user = $this->auth->getUser();
  201. $email = $this->request->post('email');
  202. $captcha = $this->request->post('captcha');
  203. if (!$email || !$captcha) {
  204. $this->error(__('Invalid parameters'));
  205. }
  206. if (!Validate::is($email, "email")) {
  207. $this->error(__('Email is incorrect'));
  208. }
  209. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  210. $this->error(__('Email already exists'));
  211. }
  212. $result = Ems::check($email, $captcha, 'changeemail');
  213. if (!$result) {
  214. $this->error(__('Captcha is incorrect'));
  215. }
  216. $verification = $user->verification;
  217. $verification->email = 1;
  218. $user->verification = $verification;
  219. $user->email = $email;
  220. $user->save();
  221. Ems::flush($email, 'changeemail');
  222. $this->success();
  223. }
  224. /**
  225. * 修改手机号
  226. *
  227. * @ApiMethod (POST)
  228. * @param string $mobile 手机号
  229. * @param string $captcha 验证码
  230. */
  231. public function changemobile()
  232. {
  233. $user = $this->auth->getUser();
  234. $mobile = $this->request->post('mobile');
  235. $captcha = $this->request->post('captcha');
  236. if (!$mobile || !$captcha) {
  237. $this->error(__('Invalid parameters'));
  238. }
  239. if (!Validate::regex($mobile, "^1\d{10}$")) {
  240. $this->error(__('Mobile is incorrect'));
  241. }
  242. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  243. $this->error(__('Mobile already exists'));
  244. }
  245. $result = Sms::check($mobile, $captcha, 'changemobile');
  246. if (!$result) {
  247. $this->error(__('Captcha is incorrect'));
  248. }
  249. $verification = $user->verification;
  250. $verification->mobile = 1;
  251. $user->verification = $verification;
  252. $user->mobile = $mobile;
  253. $user->save();
  254. Sms::flush($mobile, 'changemobile');
  255. $this->success();
  256. }
  257. /**
  258. * 第三方登录
  259. *
  260. * @ApiMethod (POST)
  261. * @param string $platform 平台名称
  262. * @param string $code Code码
  263. */
  264. public function third()
  265. {
  266. $url = url('user/index');
  267. $platform = $this->request->post("platform");
  268. $code = $this->request->post("code");
  269. $config = get_addon_config('third');
  270. if (!$config || !isset($config[$platform])) {
  271. $this->error(__('Invalid parameters'));
  272. }
  273. $app = new \addons\third\library\Application($config);
  274. //通过code换access_token和绑定会员
  275. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  276. if ($result) {
  277. $loginret = \addons\third\library\Service::connect($platform, $result);
  278. if ($loginret) {
  279. $data = [
  280. 'userinfo' => $this->auth->getUserinfo(),
  281. 'thirdinfo' => $result
  282. ];
  283. $this->success(__('Logged in successful'), $data);
  284. }
  285. }
  286. $this->error(__('Operation failed'), $url);
  287. }
  288. /**
  289. * 重置密码
  290. *
  291. * @ApiMethod (POST)
  292. * @param string $mobile 手机号
  293. * @param string $newpassword 新密码
  294. * @param string $captcha 验证码
  295. */
  296. public function resetpwd()
  297. {
  298. $type = $this->request->post("type");
  299. $mobile = $this->request->post("mobile");
  300. $email = $this->request->post("email");
  301. $newpassword = $this->request->post("newpassword");
  302. $captcha = $this->request->post("captcha");
  303. if (!$newpassword || !$captcha) {
  304. $this->error(__('Invalid parameters'));
  305. }
  306. //验证Token
  307. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  308. $this->error(__('Password must be 6 to 30 characters'));
  309. }
  310. // if ($type == 'mobile') {
  311. if (!Validate::regex($mobile, "^1\d{10}$")) {
  312. $this->error(__('Mobile is incorrect'));
  313. }
  314. $user = \app\common\model\User::getByMobile($mobile);
  315. if (!$user) {
  316. $this->error(__('User not found'));
  317. }
  318. // $ret = Sms::check($mobile, $captcha, 'resetpwd');
  319. // if (!$ret) {
  320. // $this->error(__('Captcha is incorrect'));
  321. // }
  322. // Sms::flush($mobile, 'resetpwd');
  323. // } else {
  324. // if (!Validate::is($email, "email")) {
  325. // $this->error(__('Email is incorrect'));
  326. // }
  327. // $user = \app\common\model\User::getByEmail($email);
  328. // if (!$user) {
  329. // $this->error(__('User not found'));
  330. // }
  331. // $ret = Ems::check($email, $captcha, 'resetpwd');
  332. // if (!$ret) {
  333. // $this->error(__('Captcha is incorrect'));
  334. // }
  335. // Ems::flush($email, 'resetpwd');
  336. // }
  337. //模拟一次登录
  338. $this->auth->direct($user->id);
  339. $ret = $this->auth->changepwd($newpassword, '', true);
  340. if ($ret) {
  341. $this->success(__('Reset password successful'));
  342. } else {
  343. $this->error($this->auth->getError());
  344. }
  345. }
  346. /**
  347. * 修改密码
  348. *
  349. * @ApiMethod (POST)
  350. * @param string $formerpassword 手机号
  351. * @param string $newpassword 新密码
  352. * @param string $newpassword_verify 确认密码
  353. */
  354. public function change_pwd()
  355. {
  356. $type = $this->request->post("type");
  357. $mobile = $this->request->post("mobile");
  358. $email = $this->request->post("email");
  359. $formerpassword = $this->request->post("formerpassword");
  360. $newpassword = $this->request->post("newpassword");
  361. $newpassword_verify = $this->request->post("newpassword_verify");
  362. $captcha = $this->request->post("captcha");
  363. if (!$formerpassword || !$newpassword || !$newpassword_verify) {
  364. $this->error('参数缺失');
  365. }
  366. if($newpassword != $newpassword_verify){
  367. $this->error('新密码不一致');
  368. }
  369. //验证Token
  370. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  371. $this->error(__('Password must be 6 to 30 characters'));
  372. }
  373. // if ($type == 'mobile') {
  374. // if (!Validate::regex($mobile, "^1\d{10}$")) {
  375. // $this->error(__('Mobile is incorrect'));
  376. // }
  377. $user = \app\common\model\User::getByMobile($this->auth->mobile);
  378. if (!$user) {
  379. $this->error(__('User not found'));
  380. }
  381. if($this->auth->getEncryptPassword($formerpassword,$user->salt) != $user->password){
  382. $this->error('旧密码错误');
  383. }
  384. // $ret = Sms::check($mobile, $captcha, 'resetpwd');
  385. // if (!$ret) {
  386. // $this->error(__('Captcha is incorrect'));
  387. // }
  388. // Sms::flush($mobile, 'resetpwd');
  389. // } else {
  390. // if (!Validate::is($email, "email")) {
  391. // $this->error(__('Email is incorrect'));
  392. // }
  393. // $user = \app\common\model\User::getByEmail($email);
  394. // if (!$user) {
  395. // $this->error(__('User not found'));
  396. // }
  397. // $ret = Ems::check($email, $captcha, 'resetpwd');
  398. // if (!$ret) {
  399. // $this->error(__('Captcha is incorrect'));
  400. // }
  401. // Ems::flush($email, 'resetpwd');
  402. // }
  403. //模拟一次登录
  404. $this->auth->direct($user->id);
  405. $ret = $this->auth->changepwd($newpassword, '', true);
  406. if ($ret) {
  407. $this->success(__('Reset password successful'));
  408. } else {
  409. $this->error($this->auth->getError());
  410. }
  411. }
  412. /**
  413. * 我的订单列表
  414. * @ApiMethod (POST)
  415. * @ApiReturnParams (name="uid",description="用户id")
  416. * @ApiReturnParams (name="type",description="订单类型 1订单 2报价单")
  417. * @ApiReturnParams (name="customization",description="定制金额")
  418. * @ApiReturnParams (name="goods_id",description="商品id")
  419. * @ApiReturnParams (name="goods_name",description="商品名称")
  420. * @ApiReturnParams (name="order_no",description="订单编号")
  421. * @ApiReturnParams (name="amount_real",description="订单金额")
  422. * @ApiReturnParams (name="status",description="订单流程状态(0已取消,1待支付,2已支付)")
  423. * @ApiReturnParams (name="create_time",description="创建时间")
  424. * @ApiReturnParams (name="deploy_type",description="部署方式0自己部署 1授权部署")
  425. * @ApiReturnParams (name="deploy",description="授权部署信息")
  426. * @ApiReturnParams (name="billing_status",description="开票状态 0未开票1已开票")
  427. * @ApiReturnParams (name="valid_time",description="报价单失效时间")
  428. */
  429. public function myorder(){
  430. $list = Order::all(function ($query){
  431. $query->where(['uid'=>$this->auth->id,'type'=>1])->field('id,uid,type,goods_id,goods_name,order_no,amount_real,status,create_time,deploy_type,deploy,billing_status')->order('id desc');
  432. });
  433. $bjlist = Order::all(function ($query){
  434. $query->where(['uid'=>$this->auth->id,'type'=>2,'status'=>2])->order('id desc');
  435. });
  436. $res = array_merge($list,$bjlist);
  437. $this->success('请求成功',$res);
  438. }
  439. /**
  440. * 我的订单详情
  441. * @ApiMethod (POST)
  442. * @ApiParams (name="id",description="订单id")
  443. * @ApiReturnParams (name="uid",description="用户id")
  444. * @ApiReturnParams (name="type",description="订单类型 1订单 2报价单")
  445. * @ApiReturnParams (name="customization",description="定制金额")
  446. * @ApiReturnParams (name="goods_id",description="商品id")
  447. * @ApiReturnParams (name="goods_name",description="商品名称")
  448. * @ApiReturnParams (name="order_no",description="订单编号")
  449. * @ApiReturnParams (name="amount_real",description="订单金额")
  450. * @ApiReturnParams (name="status",description="订单流程状态(0已取消,1待支付,2已支付)")
  451. * @ApiReturnParams (name="create_time",description="创建时间")
  452. * @ApiReturnParams (name="deploy_type",description="部署方式0自己部署 1授权部署")
  453. * @ApiReturnParams (name="deploy",description="授权部署信息")
  454. * @ApiReturnParams (name="billing_status",description="开票状态 0未开票1已开票")
  455. * @ApiReturnParams (name="valid_time",description="报价单失效时间")
  456. */
  457. public function myorder_details(){
  458. $list = Order::get(function ($query){
  459. $query->where(['uid'=>$this->auth->id,'type'=>1,'id'=>input('id')])->field('id,uid,type,goods_id,goods_name,order_no,amount_real,status,create_time,deploy_type,deploy,billing_status,after_sale')->order('id desc');
  460. });
  461. $this->success('请求成功',$list);
  462. }
  463. /**
  464. * 我的报价单列表
  465. * @ApiMethod (POST)
  466. * @ApiReturnParams (name="uid",description="用户id")
  467. * @ApiReturnParams (name="type",description="订单类型 1订单 2报价单")
  468. * @ApiReturnParams (name="customization",description="定制金额")
  469. * @ApiReturnParams (name="goods_id",description="商品id")
  470. * @ApiReturnParams (name="goods_name",description="商品名称")
  471. * @ApiReturnParams (name="order_no",description="订单编号")
  472. * @ApiReturnParams (name="amount_real",description="订单金额")
  473. * @ApiReturnParams (name="market",description="报价人")
  474. * @ApiReturnParams (name="status",description="订单流程状态(0已取消,1待支付,2已支付)")
  475. * @ApiReturnParams (name="create_time",description="创建时间")
  476. * @ApiReturnParams (name="deploy_type",description="部署方式0自己部署 1授权部署")
  477. * @ApiReturnParams (name="deploy",description="授权部署信息")
  478. * @ApiReturnParams (name="billing_status",description="开票状态 0未开票1已开票")
  479. * @ApiReturnParams (name="valid_time",description="报价单失效时间")
  480. */
  481. public function mypjorder(){
  482. $list = Order::all(function ($query){
  483. $query->where(['uid'=>$this->auth->id,'type'=>2])->where('status','<>',2)->field('id,uid,type,goods_id,goods_name,order_no,amount_real,market,status,create_time,deploy_type,deploy,billing_status,valid_time')->order('id desc');
  484. });
  485. // foreach ($list as $v){
  486. // $v['user'] = \app\admin\model\User::field('username,mobile,postcode,email,company,company_site')->find(['id'=>$v['uid']]);
  487. // }
  488. $this->success('请求成功',$list);
  489. }
  490. /**
  491. * 我的报价单详情
  492. * @ApiMethod (POST)
  493. * @ApiParams (name="id",description="订单id")
  494. * @ApiReturnParams (name="uid",description="用户id")
  495. * @ApiReturnParams (name="type",description="订单类型 1订单 2报价单")
  496. * @ApiReturnParams (name="customization",description="定制金额")
  497. * @ApiReturnParams (name="goods_id",description="商品id")
  498. * @ApiReturnParams (name="goods_name",description="商品名称")
  499. * @ApiReturnParams (name="order_no",description="订单编号")
  500. * @ApiReturnParams (name="amount_real",description="订单金额")
  501. * @ApiReturnParams (name="market",description="报价人")
  502. * @ApiReturnParams (name="status",description="订单流程状态(0已取消,1待支付,2已支付)")
  503. * @ApiReturnParams (name="create_time",description="创建时间")
  504. * @ApiReturnParams (name="deploy_type",description="部署方式0自己部署 1授权部署")
  505. * @ApiReturnParams (name="deploy",description="授权部署信息")
  506. * @ApiReturnParams (name="billing_status",description="开票状态 0未开票1已开票")
  507. * @ApiReturnParams (name="valid_time",description="报价单失效时间")
  508. */
  509. public function mypjorder_details(){
  510. $list = Order::get(function ($query){
  511. $query->where(['uid'=>$this->auth->id,'type'=>2,'id'=>input('id')])->field('id,uid,type,goods_id,goods_name,order_no,amount_real,market,status,create_time,deploy_type,deploy,billing_status,valid_time,customization')->order('id desc');
  512. });
  513. $list['price'] = Goods::where('id',$list['goods_id'])->value('price');
  514. $list['user'] = \app\admin\model\User::field('username,mobile,postcode,email,company,company_site')->find(['id'=>$list['uid']]);
  515. $this->success('请求成功',$list);
  516. }
  517. /**
  518. * 申请开票
  519. * @ApiMethod ("POST")
  520. * @ApiParams (name="cp_order_no",description="订单编号")
  521. * @ApiParams (name="invoice_type",description="发票类型 1普通发票2增值税发票")
  522. * @ApiParams (name="invoice_shape",description="发票形式 1纸质发票2电子发票")
  523. * @ApiParams (name="type",description="类型 1个人2企业")
  524. * @ApiParams (name="name",description="抬头名称")
  525. * @ApiParams (name="duty_paragraph",description="单位税号")
  526. * @ApiParams (name="address",description="注册地址")
  527. * @ApiParams (name="company_phone",description="公司电话")
  528. * @ApiParams (name="bank",description="银行")
  529. * @ApiParams (name="compellation",description="姓名")
  530. * @ApiParams (name="phone",description="个人电话")
  531. * @ApiParams (name="location",description="所在地")
  532. * @ApiParams (name="postcode",description="邮编")
  533. * @ApiParams (name="emial",description="邮箱")
  534. */
  535. public function make_ticket(){
  536. $uid = $this->auth->id;
  537. if(input('type')==1) {
  538. $rule = [
  539. 'cp_order_no'=>'require',
  540. 'invoice_type'=>'require',
  541. 'invoice_shape'=>'require',
  542. 'type'=>'require',
  543. 'name'=>'require',
  544. 'compellation'=>'require',
  545. 'phone'=>'require',
  546. 'location'=>'require',
  547. 'postcode'=>'require',
  548. 'emial'=>'require',
  549. ];
  550. }else if(input('type')==2){
  551. $rule = [
  552. 'cp_order_no'=>'require',
  553. 'invoice_type'=>'require',
  554. 'invoice_shape'=>'require',
  555. 'type'=>'require',
  556. 'name'=>'require',
  557. 'duty_paragraph'=>'require',
  558. 'address'=>'require',
  559. 'company_phone'=>'require',
  560. 'bank'=>'require',
  561. 'compellation'=>'require',
  562. 'phone'=>'require',
  563. 'location'=>'require',
  564. ];
  565. }
  566. $data = $this->_validate($rule);
  567. $data['uid'] = $uid;
  568. $data['order_no'] = pay_no($uid);
  569. if(!empty(Order::where('order_no', $data['cp_order_no'])->value('billing_status'))){
  570. $this->error('订单已申请发票');
  571. }
  572. DB::startTrans();
  573. try {
  574. $OrderInvoice = OrderInvoice::create($data);
  575. Order::where('order_no', $data['cp_order_no'])->update(['billing_status' => 1]);
  576. Db::commit();
  577. $this->success('申请成功',$OrderInvoice);
  578. }catch (Exception $exception){
  579. DB::rollback();
  580. $this->error($exception);
  581. return false;
  582. }
  583. }
  584. /**
  585. * 发票列表
  586. * @ApiMethod ("POST")
  587. * @ApiReturnParams (name="cp_order_no",description="产品订单编号")
  588. * @ApiReturnParams (name="order_no",description="订单编号")
  589. * @ApiReturnParams (name="invoice_type",description="发票类型 1普通发票2增值税发票")
  590. * @ApiReturnParams (name="invoice_shape",description="发票形式 1纸质发票2电子发票")
  591. * @ApiReturnParams (name="type",description="类型 1个人2企业")
  592. * @ApiReturnParams (name="name",description="抬头名称")
  593. * @ApiReturnParams (name="duty_paragraph",description="单位税号")
  594. * @ApiReturnParams (name="address",description="注册地址")
  595. * @ApiReturnParams (name="company_phone",description="公司电话")
  596. * @ApiReturnParams (name="bank",description="银行")
  597. * @ApiReturnParams (name="compellation",description="姓名")
  598. * @ApiReturnParams (name="phone",description="个人电话")
  599. * @ApiReturnParams (name="location",description="所在地")
  600. * @ApiReturnParams (name="postcode",description="邮编")
  601. * @ApiReturnParams (name="emial",description="邮箱")
  602. * @ApiReturnParams (name="apply_time",description="申请时间")
  603. * @ApiReturnParams (name="status",description="开票状态1待开票2已寄出3已完成")
  604. */
  605. public function invoice_list(){
  606. $data = OrderInvoice::all(function ($query){
  607. $query->where('uid',$this->auth->id);
  608. });
  609. foreach ($data as $v){
  610. $v['order'] = Order::where('order_no',$v['cp_order_no'])->field('create_time,goods_name,amount_real,deploy_type,deploy')->find();
  611. }
  612. $this->success('请求成功',$data);
  613. }
  614. }