ConveyPlan.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. class ConveyPlan extends Base {
  7. public function lists() {
  8. $lists = Db::name('convey_plan')
  9. ->where('user_id', $this->userId)
  10. ->where('org_id', $this->orgId)
  11. ->where('enable', 1)
  12. ->where('del', 0)
  13. ->field('id,name,weeks')
  14. ->order('id', 'desc')
  15. ->select();
  16. $week = date('w');
  17. $lists = $lists ? $lists : [];
  18. $newLists = [];
  19. foreach ($lists as $k => $v) {
  20. $weeks = $v['weeks'] ? explode(',', $v['weeks']) : [];
  21. if (in_array($week, $weeks)) {
  22. $sub = Db::name('convey_plan_addr')
  23. ->alias('cpa')
  24. ->where('cpa.plan_id', $v['id'])
  25. ->join('address ca', 'ca.id = cpa.addr_id')
  26. ->field('cpa.id,ca.title as name')
  27. ->order('cpa.sort asc')
  28. ->select();
  29. if ($sub) {
  30. unset($v['weeks']);
  31. $v['sub'] = $sub;
  32. $newLists[] = $v;
  33. }
  34. }
  35. }
  36. HelpHander::success($newLists);
  37. }
  38. public function sign() {
  39. $code = input('code', '');
  40. if (!$code) {
  41. HelpHander::error('未上传扫码结果');
  42. }
  43. $addrs = model('address')->checkAddrCode($code,2,$this->orgId);
  44. if(!$addrs){
  45. HelpHander::error('二维码不正确');
  46. }
  47. $data = [
  48. 'addr_id' => $addrs['id'],
  49. 'org_id' => $this->orgId,
  50. 'user_id' => $this->userId,
  51. 'create_time' => date('Y-m-d H:i:s'),
  52. 'create_yyyy' => date('Y'),
  53. 'create_yyyymm' => date('Ym'),
  54. 'create_yyyymmdd' => date('Ymd')
  55. ];
  56. $res = Db::name('convey_plan_record')->insert($data);
  57. if ($res) {
  58. HelpHander::success(['addr_id' => $addrs['id']], '操作成功');
  59. }
  60. else {
  61. HelpHander::error('操作失败');
  62. }
  63. }
  64. public function signlist() {
  65. $page = input('page', 1);
  66. $size = input('size', 10);
  67. $offset = ($page - 1) * $size;
  68. $map[] = ['ocl.org_id', '=', $this->orgId];
  69. $map[] = ['ocl.user_id', '=', $this->userId];
  70. $lists = Db::name('convey_plan_record')
  71. ->alias('ocl')
  72. ->field('ocl.id,ca.title,ocl.create_time')
  73. ->join('address ca', 'ca.id = ocl.addr_id')
  74. ->where($map)
  75. ->order('ocl.id desc')
  76. ->limit($offset, $size)
  77. ->select();
  78. HelpHander::success($lists ? $lists : []);
  79. }
  80. public function sample() {
  81. $barcode = input('barcode', '');
  82. $page = input('page', 1);
  83. $size = input('size', 10);
  84. $offset = ($page - 1) * $size;
  85. $map[] = ['ocl.barcode', 'like', '%' . $barcode . '%'];
  86. $map[] = ['ocl.org_id', '=', $this->orgId];
  87. $map[] = ['ocl.user_id', '=', $this->userId];
  88. $lists = Db::name('order_convey_lis')
  89. ->alias('ocl')
  90. ->field('ocl.id,ocl.barcode,ca.title,ocl.create_time')
  91. ->join('address ca', 'ca.id = ocl.addr_id')
  92. ->where($map)
  93. ->order('ocl.id desc')
  94. ->limit($offset, $size)
  95. ->select();
  96. HelpHander::success($lists);
  97. }
  98. }