GoodOfflineLog.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\DataGroup as DataGroupModel;
  4. use think\facade\Db;
  5. use think\facade\Validate;
  6. class GoodOfflineLog extends Base
  7. {
  8. //列表
  9. public function getList()
  10. {
  11. $param = $this->request->only(['start_date' => '','companyNo' => '','supplierNo' => '','relaComNo' => '', "spuCode"=>'',"good_name"=>'','end_date' => '', 'creater' => '', 'page' => 1,'size' => 15], 'post', 'trim');
  12. $where = [];
  13. if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['a.addtime', 'between', [$param['start_date'], $param['end_date']]];
  14. if ($param['creater'] != '') $where[] = ['a.creater', 'like', '%' . $param['creater'] . '%'];
  15. if ($param['spuCode'] != '') $where[] = ['a.spuCode', 'like', '%' . $param['spuCode'] . '%'];
  16. if ($param['good_name'] != '') $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
  17. if ($param['companyNo'] != '') $where[] = ['b.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  18. if ($param['supplierNo'] != '') $where[] = ['b.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  19. // if ($param['relaComNo'] != '') $where[] = ['b.companyNo|b.supplierNo', 'like', '%' . $param['relaComNo'] . '%'];
  20. // $role = $this->checkDataShare();
  21. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["createrid", "in", $role[DataGroupModel::$type_全部]];
  22. //只有level2的账号过滤数据权限
  23. if ($this->level == 2) {
  24. $role = $this->checkDataShare();
  25. $hand = resign_hand_user($this->uid, 0);
  26. if (!empty($role[DataGroupModel::$type_全部])) {
  27. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  28. $where[] = ['a.createrid', 'in', $arr];
  29. }
  30. }
  31. $count = Db::name('good_offline_log')
  32. ->alias("a")
  33. ->leftJoin("good_basic b","a.spuCode=b.spuCode")
  34. ->where($where)
  35. ->count('a.id');
  36. $list = Db::name('good_offline_log')
  37. ->alias("a")
  38. ->field('a.id,a.spuCode,a.good_name,a.creater,a.addtime,a.createrid,b.companyNo,b.supplierNo')
  39. ->leftJoin("good_basic b","a.spuCode=b.spuCode")
  40. ->where($where)
  41. ->order('a.addtime', 'desc')
  42. ->page($param['page'], $param['size'])
  43. // ->append(['is_allow_update'])
  44. // ->withAttr('is_allow_update', function ($val, $data) use ($role) {
  45. // if ($this->level == 2) return (in_array($this->roleid, [1, 33]) || in_array($data['createrid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0; //是否具有编辑权限
  46. //
  47. // })
  48. ->select()
  49. ->toArray();
  50. $userCommon=\app\admin\common\User::getIns();
  51. $supplierInfo = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'companyNo'),array_column($list,'supplierNo'))]);
  52. foreach ($list as &$value){
  53. $value['companyName'] = $supplierInfo["data"][$value['companyNo']]??"";
  54. $value['supplierName'] = $supplierInfo["data"][$value['supplierNo']]??"";
  55. }
  56. return json_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  57. }
  58. //详情
  59. public function getDetail()
  60. {
  61. $id = $this->request->post('id', null, 'trim');
  62. $val = Validate::rule(['id' => 'require|number|gt:0']);
  63. if (!$val->check(['id' => $id])) return error_show(1004, $val->getError());
  64. else {
  65. $res = Db::name('good_offline_log')
  66. ->alias('gol')
  67. ->field('gol.*,ri.result')
  68. ->where('gol.id', $id)
  69. ->leftJoin('result_info ri', 'ri.result_code=gol.offline_reason')
  70. ->find();
  71. $res['children_list'] = Db::name('good_platform')
  72. ->alias('gp')
  73. ->field('gp.id,gp.skuCode,p.platform_name,g.creater purchease,gp.creater')
  74. ->where(['gp.spuCode' => $res['spuCode']])
  75. ->whereIn('gp.skuCode', $res['skuCodes'])
  76. ->leftJoin('platform p', 'p.id=gp.platform_code')
  77. ->leftJoin('good g', 'g.spuCode=gp.spuCode')
  78. ->select()
  79. ->toArray();
  80. return app_show(0, "获取成功", $res);
  81. }
  82. }
  83. }