Intercourse.php
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace app\admin\controller\kuerp;
use app\common\controller\Backend;
use think\Db;
use Exception;
/**
* 往来单位欠款表
*
* @icon fa fa-circle-o
*/
class Intercourse extends Backend
{
public function _initialize()
{
parent::_initialize();
$setData = (new Goods())->getSetData();
$this->assign('set', $setData['setList']);
$this->assignconfig('set',$setData['setList']);
$this->assign('nowmenu', $setData['nowmenu']);
$types[] = ['name'=>'客户','value'=>1];
$types[] = ['name'=>'供应商','value'=>2];
$this->assignconfig("types", $types);
}
public function index(){
if ($this->request->isAjax()) {
$data = input();
$types = [];$keyword = '';
if(!empty($data['filter'])){
$filter = (array)json_decode($data['filter'], true);
$filter = $filter ? $filter : [];
if(!empty($filter['types_id'])){
$types = explode(',',$filter['types_id']);
}
if(!empty($filter['keyword'])){
$keyword = trim($filter['keyword']);
}
}
$customers = [];
if(empty($types) || in_array(1,$types)){
$where = [];
if(!empty($keyword)){
$where['customer_code|customer_name'] = ['like','%'.$keyword.'%'];
}
$customers = Db::name('kuerp_customers')->where((new Goods())->setWhere($where))->select();
}
$suppliers = [];
if(empty($types) || in_array(2,$types)){
$where = [];
if(!empty($keyword)){
$where['supplyer_code|supplyer_name'] = ['like','%'.$keyword.'%'];
}
$suppliers = Db::name('kuerp_suppliers')->where((new Goods())->setWhere($where))->select();
}
$list = [];
foreach ($customers as $customers_k=>$customers_v){
$list[] = [
'code' => $customers_v['customer_code'],
'name' => $customers_v['customer_name'],
'type' => 1,
'receive' => $customers_v['need_receive_account'],
];
}
foreach ($suppliers as $suppliers_k=>$suppliers_v){
$list[] = [
'code' => $suppliers_v['supplyer_code'],
'name' => $suppliers_v['supplyer_name'],
'type' => 2,
'give' => $suppliers_v['need_give_account'],
];
}
$result = array("total" => sizeof($list), "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}