ExpCost.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\admin;
  4. use Closure;
  5. use library\basic\BaseModel;
  6. use library\traits\JwtAuthModelTrait;
  7. use library\traits\ModelTrait;
  8. use think\Model;
  9. /**
  10. * @mixin \think\Model
  11. */
  12. class ExpCost extends BaseModel
  13. {
  14. use ModelTrait;
  15. use JwtAuthModelTrait;
  16. //
  17. public function expSite($sassid,$sassExpData){
  18. $expData = (new ExpCost)
  19. ->field("*,(select name from table_warehouse where id = e.warehouse_id) as warehouse_name")
  20. ->alias("e")
  21. ->where('sassid',$sassid)
  22. ->where('level_id',-1)
  23. ->select()
  24. ->toArray();
  25. $expData2 = (new ExpCost)
  26. ->field("e.*,(select title from table_express where id = e.express_id) as title")
  27. ->alias("e")
  28. ->where('e.sassid',$sassid)
  29. ->where('e.level_id','>',-1)
  30. ->select();
  31. foreach ($expData as $k => $v) {
  32. $rAr = $v;
  33. $rAr['site_money'] = $v['money'];
  34. //编辑自己的佣金
  35. foreach ($sassExpData as $vv) {
  36. if($v['warehouse_id'] == $vv['warehouse_id'] && $v['express_id'] == $vv['express_id']) {
  37. $rAr['site_money'] = $vv['money'];
  38. }
  39. }
  40. foreach ($expData2 as $vv) {
  41. if($v['warehouse_id'] == $vv['warehouse_id'] && $v['express_id'] == $vv['express_id']) {
  42. $rAr['title'] = $vv['title'];
  43. $rAr['level_'.$vv['level_id']] = $vv['money'];
  44. }
  45. }
  46. $expData[$k] = $rAr;
  47. }
  48. return $expData;
  49. }
  50. /**
  51. * 获取列表数据
  52. * @param $page
  53. * @param $where
  54. * @param $pageCount
  55. * @param $desc
  56. */
  57. public function getList2($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
  58. $data = $this
  59. ->field("ec.*,s.name as site_name,e.title as exp_name,w.name as warehouse_name")
  60. ->alias("ec")
  61. ->join('site s',"ec.sassid = s.sassid")
  62. ->join('express e',"e.id = ec.express_id")
  63. ->join('warehouse w',"w.id = ec.warehouse_id")
  64. ->where('ec.sassid',$where['sassid'])
  65. ->when(!empty($where),function ($query) use($where){
  66. if(!empty($where['level_id'])) {
  67. $query->where('ec.level_id',$where['level_id']);
  68. }
  69. })
  70. ->order($desc)
  71. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  72. ->toArray();
  73. // echo $this->getLastSql();
  74. return [$data['total'],$data['data']];
  75. }
  76. }