Order.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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,check_code,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,check_code,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. $where[$p.'.type'] = 1;//类型:1=普通,2=卡券
  71. if (!empty($status)) {
  72. if ($status == 1) {
  73. $where[$o.'.hexiao_time'] = 0;
  74. }
  75. if ($status == 2) {
  76. $where[$o.'.hexiao_time'] = ['gt',0];
  77. }
  78. }
  79. $result = $this->model->alias($o)->field($field)
  80. ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')
  81. ->join($p,$p.'.id = '.$o.'.package_id','LEFT')
  82. ->where($where)->order($o.'.createtime desc')->autopage()->select();
  83. if (!empty($result)) {
  84. foreach ($result as $key => &$value) {
  85. $value['is_check'] = !empty($value['hexiao_time']) ? 1 : 0;
  86. }
  87. $result = list_domain_image($result,['package_images']);
  88. }
  89. $this->success('获取成功', $result);
  90. } catch (Exception $e) {
  91. $this->error($e->getMessage());
  92. }
  93. }
  94. /**
  95. * 详情
  96. * @return void
  97. */
  98. public function getInfo(){
  99. try {
  100. $id = input('id',0);
  101. $payOrderId = input('pay_order_id',0);
  102. if (!empty($payOrderId)) {
  103. $orderWhere['pay_order_id'] = $payOrderId;
  104. $order = Db::name('order')->field('id')->where($orderWhere)->find();
  105. $id = isset($order['id']) ? $order['id'] : 0;
  106. }
  107. $o = 'order';
  108. $st = 'servicetype';
  109. $where[$o.'.user_id'] = $this->auth->id;
  110. $where[$o.'.id'] = $id;
  111. $field = $o.'.id,check_code,orderno,server_time,server_info,server_images,status,user_mobile,'.$o.'.user_car_number,'.
  112. $o.'.createtime,cancel_time,cancel_reason,pay_fee,appen_fee,finish_time,'.$st.'.title as `service_title`,paytype';
  113. $result = $this->model->alias($o)->field($field)
  114. ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')
  115. ->where($where)->find();
  116. if (!empty($result)) {
  117. $statusArr = [2=>'待处理',3=>'已完成',4=>'已取消'];
  118. $paytypeArr = [1=>'线下',2=>'余额',3=>'微信'];
  119. $timeArr = ['createtime','cancel_time','finish_time','server_time'];
  120. foreach ($timeArr as $k => $v) {
  121. $result[$v] = !empty($result[$v]) ? date('Y年m月d日 H:i:s', $result[$v]) : '';
  122. }
  123. $result['total_amounts'] = bcadd($result['pay_fee'],$result['appen_fee'],2);
  124. $result['status_text'] = isset($statusArr[$result['status']]) ? $statusArr[$result['status']] : '';
  125. $result['paytype_text'] = isset($paytypeArr[$result['paytype']]) ? $paytypeArr[$result['paytype']] : '';
  126. $orderAppenWhere['order_id'] = $id;
  127. $orderAppen = Db::name('order_appen')->where($orderAppenWhere)->select();
  128. $appenList = [];
  129. if (!empty($orderAppen)) {
  130. foreach ($orderAppen as $key => $value) {
  131. $appenList[] = [
  132. 'name' => $value['name'],
  133. 'price' => $value['price'],
  134. ];
  135. }
  136. }
  137. $result['appen_list'] = $appenList;
  138. $result = info_domain_image($result,['server_images']);
  139. }
  140. $this->success('获取成功', $result);
  141. } catch (Exception $e) {
  142. $this->error($e->getMessage());
  143. }
  144. }
  145. /**
  146. * 核销码
  147. * @return void
  148. */
  149. public function writeOff()
  150. {
  151. try {
  152. $id = $this->request->param('id',0);
  153. $payOrderId = input('pay_order_id',0);
  154. if (!empty($payOrderId)) {
  155. $orderWhere['pay_order_id'] = $payOrderId;
  156. $order = Db::name('order')->field('id')->where($orderWhere)->find();
  157. $id = isset($order['id']) ? $order['id'] : 0;
  158. }
  159. $companyId = $this->auth->company_id;
  160. $userId = $this->auth->id;
  161. $where['id'] = $id;
  162. $where['company_id'] = $companyId;
  163. $where['user_id'] = $userId;
  164. $modelData = $this->model->where($where)->find();
  165. if (empty($modelData)) {
  166. throw new Exception('未找到相关信息');
  167. }
  168. $text = 'order_'.$modelData['check_code'];
  169. $logo = '';
  170. $filRoute = '/uploads/temp/';
  171. $saveDir = ROOT_PATH.'public'.DS.'uploads'.DS.'temp'.DS;
  172. $fileStr = md5($text);
  173. $localpng = $saveDir.$fileStr.'.png';
  174. //验证存在直接返回
  175. $userCouponsUrl = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$filRoute.$fileStr.'.png';
  176. if (!file_exists($localpng)) {
  177. build_qrcode($text, $logo, $saveDir,$fileStr);
  178. }
  179. $result = [
  180. 'url' => $userCouponsUrl,
  181. 'check_code' => $modelData['check_code'],
  182. ];
  183. $this->success('获取成功',$result);
  184. } catch (Exception $e) {
  185. $this->error($e->getMessage());
  186. }
  187. }
  188. /**
  189. * 保养列表
  190. * @return void
  191. */
  192. public function upkeepList()
  193. {
  194. try {
  195. $serviceTypeId = input('servicetype_id',0);
  196. $carId = input('car_id',0);
  197. $carNumber = input('car_number','');
  198. $o = 'order';
  199. $st = 'servicetype';
  200. if (!empty($serviceTypeId)) {
  201. $where[$o.'.servicetype_id'] = $serviceTypeId;
  202. }
  203. if (!empty($carNumber)) {
  204. $where[$o.'.user_car_number'] = $carNumber;
  205. } else {
  206. if (!empty($carId)) {
  207. $where[$o.'.user_car_id'] = $carId;
  208. }
  209. }
  210. $where[$o.'.user_id'] = $this->auth->id;
  211. $where[$o.'.status'] = ['in',[2,3]];//状态:2=待处理,3=已完成,4=已取消
  212. $where[$st.'.is_upkeep'] = 1;//是否保养:1=是,0=否
  213. $field = $o.'.id,servicetype_id,server_info,finish_time,next_date,next_carlicheng,pay_fee,appen_fee,'.$st.'.title as `service_title`';
  214. $result = $this->model->alias($o)->field($field)
  215. ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')
  216. ->where($where)->order($o.'.finish_time desc')->autopage()->select();
  217. if (!empty($result)) {
  218. $timeArr = ['finish_time'];
  219. foreach ($result as $key => &$value) {
  220. foreach ($timeArr as $k => $v) {
  221. $value[$v] = !empty($value[$v]) ? date('Y-m-d', $value[$v]) : '';
  222. }
  223. $value['total_amounts'] = bcadd($value['pay_fee'],$value['appen_fee'],2);
  224. }
  225. }
  226. $this->success('获取成功',$result);
  227. } catch (Exception $e) {
  228. $this->error($e->getMessage());
  229. }
  230. }
  231. }