PhOrders.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\common\model\Worker;
  5. use app\hander\HelpHander;
  6. use think\App;
  7. use think\Db;
  8. use think\exception\Handle;
  9. class PhOrders extends Base
  10. {
  11. //护工工单列表
  12. public function todoList(){
  13. $page = input('page',1);
  14. $size = input('size',10);
  15. $status = input('status/d',-1);
  16. $model = new \app\common\model\PhOrders();
  17. $res = $model->workerOrderList($this->orgId,$status,$page,$size,$this->userId);
  18. HelpHander::success($res,'操作成功');
  19. }
  20. //护工工单详情
  21. public function todoDetail(){
  22. $id = input('id',0);
  23. $model = new \app\common\model\PhOrders();
  24. $res = $model->todoDetail($id);
  25. HelpHander::success($res,'操作成功');
  26. }
  27. //调度订单列表
  28. public function orderList(){
  29. $page = input('page',1);
  30. $size = input('size',10);
  31. $status = input('status/d',-1);
  32. $model = new \app\common\model\PhOrders();
  33. $res = $model->orderList1($this->orgId,$this->userId,$status,$page,$size);
  34. HelpHander::success($res,'操作成功');
  35. }
  36. //订单详情
  37. public function detail(){
  38. $id = input('id/d','');
  39. $model = new \app\common\model\PhOrders();
  40. $ret = $model->getInfo($id,$this->orgId);
  41. HelpHander::success($ret,'操作成功');
  42. }
  43. //取消订单
  44. public function cancel(){
  45. $note = input('cancelReason','','trim');
  46. $id = input('id/d',0);
  47. $model = new \app\common\model\PhOrders();
  48. $ret = $model->cancelOrder($id,$note,$this->userId);
  49. if(!$ret){
  50. HelpHander::error($model->getError());
  51. }else{
  52. HelpHander::success([],'操作成功');
  53. }
  54. }
  55. //确认完成
  56. public function finish(){
  57. $model = new \app\common\model\PhOrders();
  58. $res = $model->finishSave($this->userId,$this->orgId);
  59. if($res){
  60. HelpHander::success([],'操作成功');
  61. }else{
  62. HelpHander::error($model->getError());
  63. }
  64. }
  65. //发单
  66. public function add(){
  67. $model = new \app\common\model\PhOrders();
  68. $res = $model->addSave($this->userId,$this->orgId,1);
  69. if($res){
  70. HelpHander::success([],'操作成功');
  71. }else{
  72. HelpHander::error($model->getError());
  73. }
  74. }
  75. public function send(){
  76. $model = new \app\common\model\PhOrders();
  77. $res = $model->sendSave($this->userId,$this->orgId);
  78. if($res){
  79. HelpHander::success([],'操作成功');
  80. }else{
  81. HelpHander::error($model->getError());
  82. }
  83. }
  84. public function getWorkerAll(){
  85. $model = new Worker();
  86. $ret = $model->getAllByOrg($this->orgId);
  87. HelpHander::success($ret,'成功');
  88. }
  89. public function payOrder(){
  90. $id = input('id/d',0);
  91. $remark = input('remark','','trim');
  92. $money = input('money/f',0);
  93. $busType = input('busType/d',0);
  94. if($money <= 0){
  95. HelpHander::error('输入金额错误');
  96. }
  97. $res = model('PhOrderPay')->addSaveDispatch($this->orgId,$id,$money,$remark,$busType);
  98. if($res){
  99. HelpHander::success([],'操作成功');
  100. }else{
  101. HelpHander::error(model('PhOrderPay')->getError());
  102. }
  103. }
  104. /**
  105. * 退款
  106. */
  107. public function refund(){
  108. $res = model('PhOrderPay')->refundOrder($this->userId);
  109. if($res){
  110. HelpHander::success([],'操作成功');
  111. }else{
  112. HelpHander::error(model('PhOrderPay')->getError());
  113. }
  114. }
  115. public function payInfo(){
  116. $id = input('id/d',0);
  117. $pay = Db::name('ph_order_pay')->where('id',$id)->find();
  118. if(!$pay){
  119. HelpHander::error('记录不存在');
  120. }
  121. HelpHander::success($pay,'成功');
  122. }
  123. //护工签名
  124. public function workerSign(){
  125. $todoId = input('id/d',0);
  126. $sign = input('img','');
  127. if(!$sign){
  128. HelpHander::error('未上传签名图');
  129. }
  130. $res = Db::name('ph_todo')
  131. ->where('id',$todoId)
  132. ->update([
  133. 'sign'=>$sign
  134. ]);
  135. if(!$res){
  136. HelpHander::error('上传失败');
  137. }
  138. HelpHander::success([],'上传成功');
  139. }
  140. //员工余额记录
  141. public function balanceRecord()
  142. {
  143. $page = input('page',1);
  144. $size = input('size',10);
  145. $id = Db::name('worker')
  146. ->where('user_id',$this->userId)
  147. ->value('id');
  148. $list = Db::name('worker_balance')
  149. ->where('org_id', $this->orgId)
  150. ->where('worker_id', $id)
  151. ->order('id', 'desc')
  152. ->limit(($page-1)*$size,$size)
  153. ->select();
  154. foreach ($list as $k => $v) {
  155. $list[$k]['userName'] = Db::name('user')
  156. ->where('id', $v['user_id'])
  157. ->value('real_name');
  158. if ($v['type'] == 1) {
  159. $list[$k]['type'] = '订单结算';
  160. }else if ($v['type'] == 2) {
  161. $list[$k]['type'] = '工资结算';
  162. }else if ($v['type'] == 3) {
  163. $list[$k]['type'] = '管理员增加';
  164. }else{
  165. $list[$k]['type'] = '管理员减少';
  166. }
  167. }
  168. HelpHander::success($list);
  169. }
  170. }