PhOrders.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. public function editTodo(){
  28. $model = new \app\common\model\PhOrders();
  29. $res = $model->edit_todo($this->userId,$this->orgId);
  30. if(!$res){
  31. HelpHander::error($model->getError());
  32. }else{
  33. HelpHander::success([],'操作成功');
  34. }
  35. }
  36. //调度订单列表
  37. public function orderList(){
  38. $page = input('page',1);
  39. $size = input('size',10);
  40. $status = input('status/d',-1);
  41. $start = input('start','');
  42. $end = input('end','');
  43. $hgName = input('hgName','','trim');
  44. $brName = input('brName','','trim');
  45. $model = new \app\common\model\PhOrders();
  46. $res = $model->orderList1($this->orgId,$this->userId,$status,$start,$end,$hgName,$brName,$page,$size);
  47. HelpHander::success($res,'操作成功');
  48. }
  49. //订单详情
  50. public function detail(){
  51. $id = input('id/d','');
  52. $model = new \app\common\model\PhOrders();
  53. $ret = $model->getInfo($id,$this->orgId);
  54. HelpHander::success($ret,'操作成功');
  55. }
  56. //取消订单
  57. public function cancel(){
  58. $note = input('cancelReason','','trim');
  59. $id = input('id/d',0);
  60. $model = new \app\common\model\PhOrders();
  61. $ret = $model->cancelOrder($id,$note,$this->userId);
  62. if(!$ret){
  63. HelpHander::error($model->getError());
  64. }else{
  65. HelpHander::success([],'操作成功');
  66. }
  67. }
  68. //确认完成
  69. public function finish(){
  70. $model = new \app\common\model\PhOrders();
  71. $res = $model->finishSave($this->userId,$this->orgId);
  72. if($res){
  73. HelpHander::success([],'操作成功');
  74. }else{
  75. HelpHander::error($model->getError());
  76. }
  77. }
  78. //发单
  79. public function add(){
  80. $model = new \app\common\model\PhOrders();
  81. $res = $model->addSave($this->userId,$this->orgId,1);
  82. if($res){
  83. HelpHander::success([],'操作成功');
  84. }else{
  85. HelpHander::error($model->getError());
  86. }
  87. }
  88. public function send(){
  89. $model = new \app\common\model\PhOrders();
  90. $res = $model->sendSave($this->userId,$this->orgId);
  91. if($res){
  92. HelpHander::success([],'操作成功');
  93. }else{
  94. HelpHander::error($model->getError());
  95. }
  96. }
  97. public function getWorkerAll(){
  98. $model = new Worker();
  99. $ret = $model->getAllByOrg($this->orgId);
  100. HelpHander::success($ret,'成功');
  101. }
  102. public function payOrder(){
  103. $id = input('id/d',0);
  104. $remark = input('remark','','trim');
  105. $money = input('money/f',0);
  106. $busType = input('busType/d',0);
  107. if($money <= 0){
  108. HelpHander::error('输入金额错误');
  109. }
  110. $res = model('PhOrderPay')->addSaveDispatch($this->orgId,$id,$money,$remark,$busType);
  111. if($res){
  112. HelpHander::success([],'操作成功');
  113. }else{
  114. HelpHander::error(model('PhOrderPay')->getError());
  115. }
  116. }
  117. /**
  118. * 退款
  119. */
  120. public function refund(){
  121. $res = model('PhOrderPay')->refundOrder($this->userId);
  122. if($res){
  123. HelpHander::success([],'操作成功');
  124. }else{
  125. HelpHander::error(model('PhOrderPay')->getError());
  126. }
  127. }
  128. public function payInfo(){
  129. $id = input('id/d',0);
  130. $pay = Db::name('ph_order_pay')->where('id',$id)->find();
  131. if(!$pay){
  132. HelpHander::error('记录不存在');
  133. }
  134. HelpHander::success($pay,'成功');
  135. }
  136. //护工签名
  137. public function workerSign(){
  138. $todoId = input('id/d',0);
  139. $sign = input('img','');
  140. if(!$sign){
  141. HelpHander::error('未上传签名图');
  142. }
  143. $res = Db::name('ph_todo')
  144. ->where('id',$todoId)
  145. ->update([
  146. 'sign'=>$sign
  147. ]);
  148. if(!$res){
  149. HelpHander::error('上传失败');
  150. }
  151. HelpHander::success([],'上传成功');
  152. }
  153. //员工余额记录
  154. public function balanceRecord()
  155. {
  156. $page = input('page',1);
  157. $size = input('size',10);
  158. $id = Db::name('worker')
  159. ->where('user_id',$this->userId)
  160. ->value('id');
  161. $list = Db::name('worker_balance')
  162. ->where('org_id', $this->orgId)
  163. ->where('worker_id', $id)
  164. ->order('id', 'desc')
  165. ->limit(($page-1)*$size,$size)
  166. ->select();
  167. foreach ($list as $k => $v) {
  168. $list[$k]['userName'] = Db::name('user')
  169. ->where('id', $v['user_id'])
  170. ->value('real_name');
  171. if ($v['type'] == 1) {
  172. $list[$k]['type'] = '订单结算';
  173. }else if ($v['type'] == 2) {
  174. $list[$k]['type'] = '工资结算';
  175. }else if ($v['type'] == 3) {
  176. $list[$k]['type'] = '管理员增加';
  177. }else{
  178. $list[$k]['type'] = '管理员减少';
  179. }
  180. }
  181. HelpHander::success($list);
  182. }
  183. public function phBalanceWarning()
  184. {
  185. $page = input('page',1);
  186. $size = input('size',10);
  187. $deps = Db::name('ph_user')
  188. ->where('user', $this->userId)
  189. ->where('org_id', $this->orgId)
  190. ->value('dep');
  191. $depIds = $deps ? explode(',', $deps) : [];
  192. $list = Db::name('ph_balance_warning')
  193. ->alias('pbw')
  194. ->join('ph_orders po', 'pbw.sn = po.sn')
  195. ->where('pbw.org_id', $this->orgId)
  196. ->where('po.dep_id','in',$depIds)
  197. ->order('create_time', 'desc')
  198. ->field('pbw.*')
  199. ->limit(($page-1)*$size,$size)
  200. ->select();
  201. $list = $list?$list:[];
  202. HelpHander::success($list,'操作成功');
  203. }
  204. }