LevelOrder.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\BillApply;
  4. use app\common\model\User;
  5. use app\common\model\UserLevel;
  6. use app\common\model\LevelOrder as LOM;
  7. use app\common\model\UserLevelRank;
  8. use app\common\service\UserSynth;
  9. use EasyWeChat\Factory;
  10. use think\Db;
  11. /**
  12. * @title 会员等级订单
  13. * @controller LevelOrder
  14. * @group base
  15. */
  16. class LevelOrder extends Base
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. parent::checkLogin();
  22. }
  23. /**
  24. * @title 开通会员(续费)订单
  25. * @desc 开通会员(续费)订单
  26. * @author qc
  27. * @url /api/Level_order/createOrder
  28. * @method POST
  29. * @header name:Authorization require:1 desc:Token
  30. * @param name:level_id type:int require:1 default:0 desc:会员等级
  31. * @param name:level_key type:int require:1 default:0 desc:等级价格的key值
  32. * @return name:order_id type:int default:0 desc:订单id
  33. */
  34. public function createOrder(){
  35. $level_id = input('post.level_id');
  36. $level_key = input('post.level_key');
  37. $user_info = User::where('id',$this->user_id)->field('id,group_id,is_first,account_type')->find();
  38. if($user_info['account_type'] == 1 && $user_info['is_first'] == 0) $this->error('请联系公司管理员进行会员开通');
  39. $user_vip = UserLevelRank::getUserVipInfo($this->user_id);
  40. if(!empty($user_vip) && $user_vip['level_id'] > 1) $this->error('已是会员,请联系平台');
  41. if(!empty($user_vip) && $user_vip['user_id'] != $this->user_id) $this->error('请联系已绑定企业账号');
  42. $level_set = UserLevel::where('id', $level_id)->find()->toArray();
  43. if (!$level_set['price']) $this->error('会员价格设置有误');
  44. $level_price = json_decode($level_set['price'], true);
  45. if (!isset($level_price[$level_key])) $this->error('会员价格设置有误.');
  46. $is_renew = \app\common\model\LevelOrder::where('user_id',$this->user_id)->where('status',1)->where('pay_state',1)->count();
  47. if(!empty($user_vip)) {
  48. $cal_time = strtotime('+'.$level_price[$level_key]['time'] .' month',$user_vip['end_time']);
  49. if($cal_time > strtotime('+3 years')) $this->error('会员续费期限最多3年');
  50. }
  51. // $price_total = $is_renew && $level_price[$level_key]['renew'] > 0 && $level_price[$level_key]['renew'] ? bcmul( $level_price[$level_key]['price'], $level_price[$level_key]['renew']/100,2) : $level_price[$level_key]['price'];
  52. $order_insert = [
  53. 'user_id' => $this->user_id,
  54. 'order_no' => get_order_sn(),
  55. 'level_id' => $level_id,
  56. 'level_key' => $level_key,
  57. 'month' => $level_price[$level_key]['time'],
  58. 'level_title' => $level_price[$level_key]['title'],
  59. 'price_total' =>$is_renew ? $level_price[$level_key]['renew'] : $level_price[$level_key]['price'],
  60. ];
  61. $order_info = LOM::create($order_insert);
  62. $this->success('ok', ['order_id' => $order_info->id]);
  63. }
  64. /**
  65. * @title 获取订单详情
  66. * @desc 获取订单详情
  67. * @author qc
  68. * @method GET
  69. * @url /api/Level_order/getOrderDetail
  70. * @header name:Authorization require:1 desc:Token
  71. * @param name:order_id type:int default:-- desc:订单id
  72. * @return name:id type:int default:-- desc:订单id
  73. * @return name:order_no type:string default:-- desc:订单号
  74. * @return name:price_total type:float default:-- desc:待支付金额
  75. * @return name:level_id type:float default:-- desc:等级id
  76. * @return name:level_name type:float default:-- desc:等级名称
  77. * @return name:month type:float default:-- desc:时长(月)
  78. * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付)
  79. * @return name:pay_type type:int default:-- desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付)
  80. * @return name:pay_no type:string default:-- desc:支付号
  81. * @return name:pay_at type:string default:-- desc:支付时间
  82. * @return name:cancel_state type:int default:-- desc:取消状态(0未取消1已取消)
  83. * @return name:cancel_at type:string default:-- desc:取消时间
  84. * @return name:cancel_desc type:string default:-- desc:取消原因
  85. * @return name:cancel_desc type:string default:-- desc:取消原因
  86. * @return name:level_set type:array default:-- desc:购买会员设置
  87. * @return name:level_set.title type:string default:-- desc:标题
  88. * @return name:level_set.price type:float default:-- desc:价格
  89. * @return name:level_set.time type:int default:-- desc:时间(月)
  90. */
  91. public function getOrderDetail()
  92. {
  93. $order_id = input('get.order_id');
  94. $detail = LOM::where('id',$order_id)->find()->toArray();
  95. $level_set = UserLevel::where('id', $detail['level_id'])->find()->toArray();
  96. $detail['level_name'] = $level_set['name'];
  97. $detail['level_set'] = json_decode($level_set['price'],true)[$detail['level_key']];
  98. $this->success('',['detail'=>$detail]);
  99. }
  100. /**
  101. * @title 订单支付
  102. * @desc 订单支付
  103. * @author qc
  104. * @url /api/Level_order/payOrder
  105. * @method POST
  106. * @header name:Authorization require:1 desc:Token
  107. * @param name:order_id type:int require:1 default:0 desc:订单id
  108. * @param name:pay_type type:int require:1 default:0 desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝)
  109. * @return name:config type:array default:0 desc:小程序支付配置
  110. * @return name:config.signType type:string default:-- desc:签名类型
  111. * @return name:config.appId type:string default:-- desc:appId【h5】
  112. * @return name:config.paySign type:string default:-- desc:签名【h5】
  113. * @return name:config.nonceStr type:string default:-- desc:随机字符串【h5】
  114. * @return name:config.timeStamp type:string default:-- desc:时间戳【h5】
  115. * @return name:config.appid type:string default:-- desc:appid【微信APP】
  116. * @return name:config.sign type:string default:-- desc:签名【微信APP】
  117. * @return name:config.noncestr type:string default:-- desc:随机字符串【微信APP】
  118. * @return name:config.timestamp type:string default:-- desc:时间戳【微信APP】
  119. * @return name:config.partnerid type:string default:-- desc:商户号
  120. * @return name:config.prepayid type:string default:-- desc:唯一支付号
  121. * @return name:config.package type:string default:-- desc:package
  122. * @return name:config.mch_id type:string default:-- desc:商户号(H5)
  123. * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
  124. * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
  125. * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
  126. * @return name:code_url type:string default:-- desc:付款码url
  127. * @return name:openid type:string default:-- desc:openid
  128. */
  129. public function payOrder()
  130. {
  131. $order_id = input('post.order_id');
  132. $pay_type = input('post.pay_type',1);
  133. $order_info = LOM::where('id',$order_id)->find()->toArray();
  134. if($order_info['status'] != 0) $this->error('订单状态错误');
  135. if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
  136. if($order_info['price_total'] <= 0) $this->error('订单金额错误');
  137. $user_vip = UserLevelRank::getUserVipInfo($this->user_id);
  138. if(!empty($user_vip)) {
  139. $cal_time = strtotime('+'.$order_info['month'] .' month',$user_vip['end_time']);
  140. if($cal_time > strtotime('+3 years')) $this->error('会员续费期限最多3年');
  141. }
  142. if(!empty($user_vip) && $user_vip['user_id'] != $this->user_id) $this->error('请联系已绑定企业账号');
  143. $pay_no = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号
  144. if(!$order_info['pay_no']) LOM::where('id',$order_id)->update(['pay_no'=>$pay_no]);
  145. $user_info = User::where('id',$this->user_id)->find()->toArray();
  146. $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid']];
  147. Db::startTrans();
  148. LOM::where('id',$order_id)->update(['pay_type'=>$pay_type]);
  149. try {
  150. switch ($pay_type){
  151. case 1://微信
  152. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  153. // $notify_url = 'https://gaoyixia.hdlkeji.com/api/we_chat_pay/LevelOrderNotify';
  154. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
  155. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  156. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  157. $pay_config['config']['pay_no'] = $pay_no;
  158. $pay_config['config']['notify_url'] = $notify_url;
  159. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  160. $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
  161. $ret_data['config'] = $pay_config['config'];
  162. break;
  163. case 2 :
  164. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  165. $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
  166. $config = Alipay::ali_pay_h5('订单支付',$pay_no,$order_info['price_total'],$notify_url,$return_url);
  167. $ret_data['config']['ali_url'] = $config;
  168. $ret_data['ali_url'] = $config;
  169. break;
  170. case 3:
  171. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  172. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'APP');
  173. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  174. $ret_data['config'] = $pay_config['config'];
  175. break;
  176. case 4:
  177. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  178. $config = Alipay::ali_pay('订单支付',$pay_no,$order_info['price_total'],$notify_url);
  179. $ret_data['config']['ali_url'] = $config;
  180. $ret_data['ali_url'] = $config;
  181. break;
  182. case 5 :
  183. if(!$user_info['openid']) $this->exception('请绑定openid');
  184. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  185. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
  186. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  187. $ret_data['config'] = $pay_config['config'];
  188. break;
  189. }
  190. Db::commit();
  191. }catch (\Exception $e){
  192. $this->is_commit = false;
  193. $this->ret_msg = $e->getMessage();
  194. Db::rollback();
  195. }
  196. $this->transReturn($ret_data);
  197. }
  198. /**
  199. * @title 开通会员
  200. * @desc 开通会员
  201. * @author qc
  202. * @url /api/Level_order/payOrderNew
  203. * @method POST
  204. * @header name:Authorization require:1 desc:Token
  205. * @param name:level_id type:int require:1 default:0 desc:会员等级
  206. * @param name:level_key type:int require:1 default:0 desc:等级价格的key值
  207. * @param name:pay_type type:int require:1 default:0 desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付,6微信pc,7pc支付宝)
  208. * @return name:config type:array default:0 desc:支付配置
  209. * @return name:config.appId type:string default:-- desc:公众账号ID
  210. * @return name:config.signType type:string default:-- desc:签名类型
  211. * @return name:config.paySign type:string default:-- desc:签名
  212. * @return name:config.nonceStr type:string default:-- desc:随机字符串
  213. * @return name:config.timestamp type:string default:-- desc:时间戳
  214. * @return name:config.partnerid type:string default:-- desc:商户号
  215. * @return name:config.prepayid type:string default:-- desc:唯一支付号
  216. * @return name:config.package type:string default:-- desc:package
  217. * @return name:config.mch_id type:string default:-- desc:商户号(H5)
  218. * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
  219. * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
  220. * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
  221. * @return name:config.ali_url type:int default:-- desc:支付宝支付链接
  222. * @return name:code_url type:string default:-- desc:付款码url
  223. * @return name:openid type:string default:-- desc:openid
  224. */
  225. public function payOrderNew()
  226. {
  227. $level_id = input('post.level_id');
  228. $level_key = input('post.level_key');
  229. $pay_type = input('post.pay_type',1);
  230. $user_info = User::where('id',$this->user_id)->find();
  231. if($user_info['account_type'] == 1 && $user_info['is_first'] == 0) $this->error('请联系公司管理员进行会员开通');
  232. $is_renew = \app\common\model\LevelOrder::where('user_id',$this->user_id)->where('status',1)->where('pay_state',1)->count();
  233. $level_set = UserLevel::where('id', $level_id)->find()->toArray();
  234. if (!$level_set['price']) $this->error('会员价格设置有误');
  235. $level_price = json_decode($level_set['price'], true);
  236. if (!isset($level_price[$level_key])) $this->error('会员价格设置有误.');
  237. //$price_total = $is_renew && $level_price[$level_key]['renew'] > 0 && $level_price[$level_key]['renew'] ? bcmul( $level_price[$level_key]['price'], $level_price[$level_key]['renew']/100,2) : $level_price[$level_key]['price'];
  238. $order_insert = [
  239. 'user_id' => $this->user_id,
  240. 'order_no' => get_order_sn(),
  241. 'level_id' => $level_id,
  242. 'level_key' => $level_key,
  243. 'pay_type' => $pay_type,
  244. 'month' => $level_price[$level_key]['time'],
  245. 'level_title' => $level_price[$level_key]['title'],
  246. 'price_total' =>$is_renew ? $level_price[$level_key]['renew'] : $level_price[$level_key]['price'],
  247. 'pay_no' =>get_order_sn()
  248. ];
  249. $user_vip = UserLevelRank::getUserVipInfo($this->user_id);
  250. if(!empty($user_vip) && $user_vip['level_id'] > 1) $this->error('已是会员,请联系平台');
  251. if(!empty($user_vip) && $user_vip['user_id'] != $this->user_id) $this->error('请联系已绑定企业账号');
  252. if(!empty($user_vip)) {
  253. $cal_time = strtotime('+'.$order_insert['month'] .' month',$user_vip['end_time']);
  254. if($cal_time > strtotime('+3 years')) $this->error('会员续费期限最多3年');
  255. }
  256. $order_info = LOM::create($order_insert);
  257. $order_info = $order_info->toArray();
  258. $pay_no = $order_info['pay_no'];
  259. $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid'],'order_id'=>$order_info['id']];
  260. Db::startTrans();
  261. try {
  262. switch ($pay_type){
  263. case 1://微信
  264. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  265. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
  266. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  267. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  268. $pay_config['config']['pay_no'] = $pay_no;
  269. $pay_config['config']['notify_url'] = $notify_url;
  270. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  271. $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
  272. $ret_data['config'] = $pay_config['config'];
  273. break;
  274. case 2 :
  275. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  276. $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
  277. $config = Alipay::ali_pay_h5('订单支付',$pay_no,$order_info['price_total'],$notify_url,$return_url);
  278. $ret_data['config']['ali_url'] = $config;
  279. $ret_data['ali_url'] = $config;
  280. break;
  281. case 3:
  282. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  283. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'APP');
  284. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  285. $ret_data['config'] = $pay_config['config'];
  286. break;
  287. case 4:
  288. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  289. $config = Alipay::ali_pay('订单支付',$pay_no,$order_info['price_total'],$notify_url);
  290. $ret_data['config']['ali_url'] = $config;
  291. $ret_data['ali_url'] = $config;
  292. break;
  293. case 5 :
  294. if(!$user_info['openid']) $this->exception('请绑定openid');
  295. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  296. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'NATIVE',$user_info['openid']);
  297. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  298. $ret_data['config'] = $pay_config['config'];
  299. break;
  300. case 6:
  301. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  302. /*$app = Factory::payment(config('app.wx_pay'));
  303. $pay_config = $app->order->unify([
  304. 'body' => '订单支付',
  305. 'out_trade_no' => $pay_no,
  306. 'total_fee' => $order_info['price_total']*100,
  307. 'notify_url' => $notify_url, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  308. 'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
  309. ]);*/
  310. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'] ,$notify_url,'NATIVE');
  311. $ret_data['config'] = $pay_config['config'];
  312. $ret_data['code_url'] = $pay_config['pc_pay_url'];
  313. break;
  314. case 7:
  315. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  316. $return_url ='https://'.$_SERVER['HTTP_HOST']."/pc/#/vip-member";
  317. $config = Alipay::ali_pay_pc('订单支付',$pay_no,$order_info['price_total'],$notify_url,$return_url);
  318. $ret_data['config']['ali_url'] = $config;
  319. $ret_data['ali_url'] = $config;
  320. break;
  321. }
  322. Db::commit();
  323. }catch (\Exception $e){
  324. $this->is_commit = false;
  325. $this->ret_msg = $e->getMessage();
  326. Db::rollback();
  327. }
  328. $this->transReturn($ret_data);
  329. }
  330. /**
  331. * @title 获取订单列表
  332. * @desc 获取订单列表
  333. * @author qc
  334. * @method GET
  335. * @url /api/Level_order/getOrderList
  336. * @header name:Authorization require:1 desc:Token
  337. * @param name:page type:int default:1 desc:页数
  338. * @param name:page_num type:int default:20 desc:每页数
  339. * @return name:order_no type:string default:-- desc:订单号
  340. * @return name:price_total type:float default:-- desc:待支付金额
  341. * @return name:level_id type:float default:-- desc:等级id
  342. * @return name:level_name type:float default:-- desc:等级名称
  343. * @return name:level_title type:float default:-- desc:等级标题
  344. * @return name:month type:float default:-- desc:时长(月)
  345. * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付)
  346. * @return name:bill_apply type:int default:-- desc:是否申请发票【0否1是】
  347. * @return name:create_at type:string default:-- desc:时间
  348. * @return name:level_logo type:string default:-- desc:等级LOGO
  349. * @return name:pay_type type:int default:-- desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付,6微信pc)
  350. * @return name:bill_info type:array default:-- desc:发票详情
  351. */
  352. public function getOrderList()
  353. {
  354. $field = 'id,level_id,level_key,month,price_total,pay_type,order_no,create_at,level_title';
  355. $list = \app\common\model\LevelOrder::field($field)->where(['user_id'=>$this->user_id,'pay_state'=>1])
  356. ->order('id desc ')->limit($this->off_set,$this->page_num)->select()->toArray();
  357. array_walk($list,function (&$v){
  358. $v['bill_apply'] = BillApply::checkBillApply($v['id'],1) ? 1 : 0;
  359. $level_info = UserLevel::where('id',$v['level_id'])->find()->toArray();
  360. $v['level_name'] =$level_info['name'];
  361. $v['level_logo'] =$level_info['logo'];
  362. $bill_info = BillApply::where(['order_type'=>1,'order_id'=>$v['id']])
  363. ->alias('b')->field('b.id,b.type,b.header,b.status,b.email,b.phone,b.bill_img,b.bill_time,b.remark,identify_number,b.create_at,t.title type_title,a.price_total money')
  364. ->leftJoin('BillType t','t.id = b.type')
  365. ->leftJoin('LevelOrder a','a.id = b.order_id')
  366. ->find();
  367. if($bill_info) $bill_info = $bill_info->toArray();
  368. $v['bill_info'] = $bill_info;
  369. });
  370. $total_num = \app\common\model\LevelOrder::field($field)->where(['user_id'=>$this->user_id,'pay_state'=>1])->count();
  371. $this->success('ok',['list'=>$list,'total_num'=>numTransform($total_num),'total_count'=>$total_num,'page_num'=>$this->page_num]);
  372. }
  373. /**
  374. *
  375. * @title 申请开票
  376. * @desc 申请开票
  377. * @author qc
  378. * @method POST
  379. * @url /api/Level_order/applyBill
  380. * @header name:Authorization require:1 desc:Token
  381. * @param name:order_id type:string default:1 desc:订单id
  382. * @param name:type type:int default:-- desc:类型id
  383. * @param name:header type:string default:-- desc:抬头名称[公司名称||个人名称]
  384. * @param name:identify_number type:string default:-- desc:纳税人识别号
  385. * @param name:email type:string default:-- desc:邮箱
  386. * @param name:remark type:string default:-- desc:备注
  387. */
  388. public function applyBill()
  389. {
  390. $order_id = input('post.order_id');
  391. /* $type = input('post.type');
  392. $header = input('post.header');
  393. $identify_number = input('post.identify_number');
  394. $address = input('post.address');
  395. $bank = input('post.bank');
  396. $card_no = input('post.card_no');
  397. $remark = input('post.remark');
  398. $phone = input('post.phone');
  399. $email = input('post.email');*/
  400. $post = input('post.');
  401. $order_info = \app\common\model\LevelOrder::where('id',$order_id)->find()->toArray();
  402. if(!$order_info['pay_state'])$this->error('订单未支付');
  403. if(BillApply::checkBillApply($order_id,1)) $this->error('已申请开票');
  404. $ret_val = UserSynth::buildBillApply($this->user_id, $order_id, 1,$post,0,1,$post['remark']);
  405. if($ret_val['code'] != 200) $this->error($ret_val['msg']);
  406. $this->success('申请成功');
  407. }
  408. /**
  409. * @title 获取发票详情
  410. * @desc 获取发票详情
  411. * @author qc
  412. * @url /api/Level_order/getBillInfo
  413. * @method GET
  414. * @param name:id type:int require default:-- desc:订单id
  415. * @return name:id type:array default:-- desc:票详情id
  416. * @return name:header type:string default:0 desc:抬头
  417. * @return name:type_title type_title:int default:0 desc:发票类型
  418. * @return name:email type:string default:0 desc:邮箱
  419. * @return name:create_at type:string default:0 desc:申请时间
  420. * @return name:phone type:string default:0 desc:电话
  421. * @return name:status type:int default:0 desc:状态(0申请中1已开票2已完成)
  422. * @return name:identify_number type:string default:0 desc:纳税人识别号
  423. * @return name:send_type type:string default:1 desc:1点子发票2纸质发票
  424. * @return name:remark type:string default:0 desc:备注
  425. * @return name:bill_img type:string default:0 desc:点子发票【图片】
  426. * @return name:bill_time type:string default:0 desc:开票时间
  427. *
  428. */
  429. public function getBillInfo()
  430. {
  431. $info = BillApply::where(['order_type'=>1,'order_id'=>input('get.id')])
  432. ->alias('b')->field('b.id,b.type,b.header,b.status,b.email,b.phone,b.bill_img,b.bill_time,b.remark,identify_number,b.create_at,t.title type_title,a.price_total money')
  433. ->leftJoin('BillType t','t.id = b.type')
  434. ->leftJoin('LevelOrder a','a.id = b.order_id')
  435. ->find();
  436. if(empty($info)) $this->error('该订单未申请发票');
  437. $info = $info->toArray();
  438. $this->success('ok',['detail'=>$info]);
  439. }
  440. }