Order.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Exception;
  6. class Order extends Api
  7. {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = '*';
  10. protected $model = null;
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. $this->model = Db::name('order');
  15. }
  16. /**
  17. * 列表
  18. * @return void
  19. */
  20. public function getList(){
  21. try {
  22. $status = input('status',0);//状态:1=待支付,2=待处理,3=已完成,4=已取消
  23. $o = 'order';
  24. $st = 'servicetype';
  25. $field = $o.'.id,orderno,server_time,server_info,server_images,status,user_mobile,'.$o.'.user_car_number,'.
  26. $o.'.createtime,cancel_time,cancel_reason,pay_fee,appen_fee,finish_time,'.$st.'.title as `service_title`,paytype';
  27. $where[$o.'.user_id'] = $this->auth->id;
  28. $where[$o.'.company_id'] = $this->auth->company_id;
  29. if (!empty($status)) {
  30. $where[$o.'.status'] = $status;
  31. }
  32. $result = $this->model->alias($o)->field($field)
  33. ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')
  34. ->where($where)->order($o.'.createtime desc')->autopage()->select();
  35. if (!empty($result)) {
  36. $statusArr = [2=>'待处理',3=>'已完成',4=>'已取消'];
  37. $paytypeArr = [1=>'线下',2=>'余额',3=>'微信'];
  38. $timeArr = ['createtime','cancel_time','finish_time','server_time'];
  39. foreach ($result as $key => &$value) {
  40. foreach ($timeArr as $k => $v) {
  41. $value[$v] = !empty($value[$v]) ? date('Y年m月d日 H:i:s', $value[$v]) : '';
  42. }
  43. $value['total_amounts'] = bcadd($value['pay_fee'],$value['appen_fee'],2);
  44. $value['status_text'] = isset($statusArr[$value['status']]) ? $statusArr[$value['status']] : '';
  45. $value['paytype_text'] = isset($paytypeArr[$value['paytype']]) ? $paytypeArr[$value['paytype']] : '';
  46. }
  47. $result = list_domain_image($result,['server_images']);
  48. }
  49. $this->success('获取成功', $result);
  50. } catch (Exception $e) {
  51. $this->error($e->getMessage());
  52. }
  53. }
  54. /**
  55. * 套餐列表
  56. * @return void
  57. */
  58. public function getPackageList(){
  59. try {
  60. $status = input('status',0);//状态:1=待使用,2=已核销
  61. $o = 'order';
  62. $st= 'servicetype';
  63. $p = 'package';
  64. $field = $o.'.id,server_info,'.$o.'.servicetype_id,'.$st.'.title as `service_title`,'.$p.'.title as `package_title`,'.
  65. $p.'.images as `package_images`,hexiao_time';
  66. $where[$o.'.user_id'] = $this->auth->id;
  67. $where[$o.'.company_id'] = $this->auth->company_id;
  68. $where[$o.'.ordertype'] = 3;//类型:1=预约下单,2=在线下单,3=套餐订单
  69. $where[$o.'.status'] = ['in',[1,2,3]];//状态:2=待处理,3=已完成,4=已取消
  70. if (!empty($status)) {
  71. if ($status == 1) {
  72. $where[$o.'.hexiao_time'] = 0;
  73. }
  74. if ($status == 2) {
  75. $where[$o.'.hexiao_time'] = ['gt',0];
  76. }
  77. }
  78. $result = $this->model->alias($o)->field($field)
  79. ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')
  80. ->join($p,$p.'.id = '.$o.'.package_id','LEFT')
  81. ->where($where)->order($o.'.createtime desc')->autopage()->select();
  82. if (!empty($result)) {
  83. foreach ($result as $key => &$value) {
  84. $value['is_check'] = !empty($value['hexiao_time']) ? 1 : 0;
  85. }
  86. $result = list_domain_image($result,['package_images']);
  87. }
  88. $this->success('获取成功', $result);
  89. } catch (Exception $e) {
  90. $this->error($e->getMessage());
  91. }
  92. }
  93. /**
  94. * 详情
  95. * @return void
  96. */
  97. public function getInfo(){
  98. try {
  99. $id = input('id',0);
  100. $payOrderId = input('pay_order_id',0);
  101. if (!empty($payOrderId)) {
  102. $orderWhere['pay_order_id'] = $payOrderId;
  103. $order = Db::name('order')->field('id')->where($orderWhere)->find();
  104. $id = isset($order['id']) ? $order['id'] : 0;
  105. }
  106. $o = 'order';
  107. $st = 'servicetype';
  108. $where[$o.'.user_id'] = $this->auth->id;
  109. $where[$o.'.id'] = $id;
  110. $field = $o.'.id,orderno,server_time,server_info,server_images,status,user_mobile,'.$o.'.user_car_number,'.
  111. $o.'.createtime,cancel_time,cancel_reason,pay_fee,appen_fee,finish_time,'.$st.'.title as `service_title`,paytype';
  112. $result = $this->model->alias($o)->field($field)
  113. ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')
  114. ->where($where)->find();
  115. if (!empty($result)) {
  116. $statusArr = [2=>'待处理',3=>'已完成',4=>'已取消'];
  117. $paytypeArr = [1=>'线下',2=>'余额',3=>'微信'];
  118. $timeArr = ['createtime','cancel_time','finish_time','server_time'];
  119. foreach ($timeArr as $k => $v) {
  120. $result[$v] = !empty($result[$v]) ? date('Y年m月d日 H:i:s', $result[$v]) : '';
  121. }
  122. $result['total_amounts'] = bcadd($result['pay_fee'],$result['appen_fee'],2);
  123. $result['status_text'] = isset($statusArr[$result['status']]) ? $statusArr[$result['status']] : '';
  124. $result['paytype_text'] = isset($paytypeArr[$result['paytype']]) ? $paytypeArr[$result['paytype']] : '';
  125. $orderAppenWhere['order_id'] = $id;
  126. $orderAppen = Db::name('order_appen')->where($orderAppenWhere)->select();
  127. $appenList = [];
  128. if (!empty($orderAppen)) {
  129. foreach ($orderAppen as $key => $value) {
  130. $appenList[] = [
  131. 'name' => $value['name'],
  132. 'price' => $value['price'],
  133. ];
  134. }
  135. }
  136. $result['appen_list'] = $appenList;
  137. $result = info_domain_image($result,['server_images']);
  138. }
  139. $this->success('获取成功', $result);
  140. } catch (Exception $e) {
  141. $this->error($e->getMessage());
  142. }
  143. }
  144. /**
  145. * 核销码
  146. * @return void
  147. */
  148. public function writeOff()
  149. {
  150. try {
  151. $id = $this->request->param('id',0);
  152. $payOrderId = input('pay_order_id',0);
  153. if (!empty($payOrderId)) {
  154. $orderWhere['pay_order_id'] = $payOrderId;
  155. $order = Db::name('order')->field('id')->where($orderWhere)->find();
  156. $id = isset($order['id']) ? $order['id'] : 0;
  157. }
  158. $companyId = $this->auth->company_id;
  159. $userId = $this->auth->id;
  160. $where['id'] = $id;
  161. $where['company_id'] = $companyId;
  162. $where['user_id'] = $userId;
  163. $modelData = $this->model->where($where)->find();
  164. if (empty($modelData)) {
  165. throw new Exception('未找到相关信息');
  166. }
  167. $text = 'order_'.$modelData['check_code'];
  168. $logo = '';
  169. $filRoute = '/uploads/temp/';
  170. $saveDir = ROOT_PATH.'public'.DS.'uploads'.DS.'temp'.DS;
  171. $fileStr = md5($text);
  172. $localpng = $saveDir.$fileStr.'.png';
  173. //验证存在直接返回
  174. $userCouponsUrl = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$filRoute.$fileStr.'.png';
  175. if (!file_exists($localpng)) {
  176. build_qrcode($text, $logo, $saveDir,$fileStr);
  177. }
  178. $result = [
  179. 'url' => $userCouponsUrl,
  180. ];
  181. $this->success('获取成功',$result);
  182. } catch (Exception $e) {
  183. $this->error($e->getMessage());
  184. }
  185. }
  186. /**
  187. * 保养列表
  188. * @return void
  189. */
  190. public function upkeepList()
  191. {
  192. try {
  193. $serviceTypeId = input('servicetype_id',0);
  194. $carId = input('car_id',0);
  195. $carNumber = input('car_number','');
  196. $o = 'order';
  197. $st = 'servicetype';
  198. if (!empty($serviceTypeId)) {
  199. $where[$o.'.servicetype_id'] = $serviceTypeId;
  200. }
  201. if (!empty($carNumber)) {
  202. $where[$o.'.user_car_number'] = $carNumber;
  203. } else {
  204. if (!empty($carId)) {
  205. $where[$o.'.user_car_id'] = $carId;
  206. }
  207. }
  208. $where[$o.'.user_id'] = $this->auth->id;
  209. $where[$o.'.status'] = ['in',[2,3]];//状态:2=待处理,3=已完成,4=已取消
  210. $where[$st.'.is_upkeep'] = 1;//是否保养:1=是,0=否
  211. $field = $o.'.id,servicetype_id,server_info,finish_time,next_date,next_carlicheng,pay_fee,appen_fee,'.$st.'.title as `service_title`';
  212. $result = $this->model->alias($o)->field($field)
  213. ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')
  214. ->where($where)->order($o.'.finish_time desc')->autopage()->select();
  215. if (!empty($result)) {
  216. $timeArr = ['finish_time'];
  217. foreach ($result as $key => &$value) {
  218. foreach ($timeArr as $k => $v) {
  219. $value[$v] = !empty($value[$v]) ? date('Y-m-d', $value[$v]) : '';
  220. }
  221. $value['total_amounts'] = bcadd($value['pay_fee'],$value['appen_fee'],2);
  222. }
  223. }
  224. $this->success('获取成功',$result);
  225. } catch (Exception $e) {
  226. $this->error($e->getMessage());
  227. }
  228. }
  229. }