Headquarters.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\Account;
  5. use app\model\AccountCompany;
  6. use think\Exception;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. use think\facade\Cache;
  10. //【公司汇总】
  11. class Headquarters extends BaseController
  12. {
  13. //列表
  14. public function getList()
  15. {
  16. $post = $this->request->only(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' => '', 'account_id' => '', 'type' => ''], 'post');
  17. $condition = [['is_del', '=', 0]];
  18. if ($post['code'] != '') $condition[] = is_array($post['code']) ? ['code', 'in', $post['code']] : ['code', 'like', "%{$post['code']}%"];
  19. if ($post['name'] != '') $condition[] = ['name', 'like', "%{$post['name']}%"];
  20. if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
  21. if ($post['level'] != 1) {
  22. $companyCode = Db::name('account_company')
  23. ->where(['account_id' => $post['account_id'], 'is_del' => 0, 'status' => 1])
  24. ->column('companyCode');
  25. $condition[] = ['code', 'in', $companyCode];
  26. }
  27. // if ($post['type'] !== '') $condition[] = ['', 'exp', Db::raw("FIND_IN_SET({$post['type']},type)")];
  28. if ($post['type'] !== '') $condition[] = ['type', '=', $post['type']];
  29. //兼容原有各个接口的筛选
  30. $count = Db::name('supplier')
  31. ->where($condition)
  32. ->count('id');
  33. $list = Db::name('headquarters')
  34. ->field('id,code,name,type,status,addtime,relation_code')
  35. ->where($condition)
  36. ->page($post['page'], $post['size'])
  37. ->order(['addtime' => 'desc', 'id' => 'desc'])
  38. ->select()
  39. ->toArray();
  40. return json_show(0, '获取成功', ['list' => $list, 'count' => $count]);
  41. }
  42. //添加
  43. public function add()
  44. {
  45. $post = $this->request->filter('trim')->post();
  46. Db::startTrans();
  47. try {
  48. switch ($post['type']) {
  49. case 1:
  50. Db::name('business')->insert($post['data']);
  51. break;
  52. case 2:
  53. Db::name('customer_info')->insert($post['data']);
  54. break;
  55. case 3:
  56. Db::name('supplier')->insert($post['data']);
  57. break;
  58. }
  59. Db::name('headquarters')
  60. ->insert([
  61. 'code' => $post['code'],
  62. 'name' => $post['name'],
  63. 'type' => $post['type'],
  64. 'invoice_title' => $post['invoice_title'],
  65. 'invoice_people' => $post['invoice_people'],
  66. 'invoice_addr' => $post['invoice_addr'],
  67. 'invoice_code' => $post['invoice_code'],
  68. 'invoice_bank' => $post['invoice_bank'],
  69. 'invoice_bankNo' => $post['invoice_bankNo'],
  70. 'invoice_img' => $post['invoice_img'],
  71. 'remark' => $post['remark'],
  72. 'status' => $post['status'],
  73. 'is_del' => 0,
  74. 'creater' => $post['creater'],
  75. 'createrid' => $post['createrid'],
  76. 'addtime' => date('Y-m-d H:i:s'),
  77. 'updater' => $post['updater'],
  78. 'updaterid' => $post['updaterid'],
  79. 'updatetime' => date('Y-m-d H:i:s'),
  80. ]);
  81. Db::commit();
  82. Cache::store("redis")->handler()->lpush("companycopy",$post);
  83. return json_show(0, '添加成功');
  84. } catch (Exception $e) {
  85. Db::rollback();
  86. return json_show(1002, '添加失败,' . $e->getMessage());
  87. }
  88. }
  89. //编辑
  90. public function update()
  91. {
  92. $post = $this->request->filter('trim')->post();
  93. Db::startTrans();
  94. try {
  95. switch ($post['type']) {
  96. case 1:
  97. Db::name('business')->where(['companyNo' => $post['data']['companyNo'], 'is_del' => 0])->update($post['data']);
  98. break;
  99. case 2:
  100. Db::name('customer_info')->where(['companyNo' => $post['data']['companyNo'], 'is_del' => 0])->update($post['data']);
  101. break;
  102. case 3:
  103. Db::name('supplier')->where(['code' => $post['data']['code'], 'is_del' => 0])->update($post['data']);
  104. break;
  105. }
  106. Db::name('headquarters')
  107. ->where(['code' => $post['code'], 'is_del' => 0])
  108. ->update([
  109. 'code' => $post['code'],
  110. 'name' => $post['name'],
  111. 'type' => $post['type'],
  112. 'invoice_title' => $post['invoice_title'],
  113. 'invoice_people' => $post['invoice_people'],
  114. 'invoice_addr' => $post['invoice_addr'],
  115. 'invoice_code' => $post['invoice_code'],
  116. 'invoice_bank' => $post['invoice_bank'],
  117. 'invoice_bankNo' => $post['invoice_bankNo'],
  118. 'invoice_img' => $post['invoice_img'],
  119. 'remark' => $post['remark'],
  120. 'updater' => $post['updater'],
  121. 'updaterid' => $post['updaterid'],
  122. 'updatetime' => date('Y-m-d H:i:s'),
  123. ]);
  124. Db::commit();
  125. Cache::store("redis")->handler()->lpush("companycopy",json_encode($post,JSON_UNESCAPED_UNICODE));
  126. return json_show(0, '修改成功');
  127. } catch (Exception $e) {
  128. Db::rollback();
  129. return json_show(1002, '修改失败,' . $e->getMessage());
  130. }
  131. }
  132. //详情
  133. public function info()
  134. {
  135. $code = $this->request->post('code', '', 'trim');
  136. if ($code == '') return json_show(1003, "参数 code 不能为空");
  137. $res = Db::name('headquarters')
  138. ->field(true)
  139. ->where(['code' => $code, 'is_del' => 0])
  140. ->findOrEmpty();
  141. if (empty($res)) return json_show(1004, '未找到相关汇总信息');
  142. switch ($res['type']) {
  143. case 1:
  144. $child = Db::name('business')
  145. ->field(true)
  146. ->where(['companyNo' => $code, 'is_del' => 0])
  147. ->findOrEmpty();
  148. break;
  149. case 2:
  150. $child = Db::name('customer_info')
  151. ->where(['companyNo' => $code, 'is_del' => 0])
  152. ->findOrEmpty();
  153. break;
  154. case 3:
  155. $child = Db::name('supplier')
  156. ->where(['code' => $code, 'is_del' => 0])
  157. ->findOrEmpty();
  158. break;
  159. }
  160. $res['child'] = $child;
  161. $res['relation_name'] =$res['relation_code']==""?'': Db::name('headquarters')->where('code',$res['relation_code'])
  162. ->value('name','');
  163. return json_show(0, '获取成功', $res);
  164. }
  165. //删除
  166. public function delete()
  167. {
  168. $param = $this->request->only(['ids', 'type', 'updater', 'updaterid'], 'post', 'trim');
  169. $val = Validate::rule([
  170. 'ids' => 'require|array|max:100',
  171. 'type|类别' => 'require|number|in:1,2,3',
  172. 'updater|操作人' => 'require|max:255',
  173. 'updaterid|操作人id' => 'require|number|gt:0',
  174. ]);
  175. if (!$val->check($param)) return json_show(1004, $val->getError());
  176. Db::startTrans();
  177. try {
  178. $date = date('Y-m-d H:i:s');
  179. $codes = [];
  180. switch ($param['type']) {
  181. case 1:
  182. $where = [['is_del', '=', 0], ['id', 'in', $param['ids']]];
  183. $codes = Db::name('business')->where($where)->column('companyNo');
  184. Db::name('business')->where($where)->update(['is_del' => 1, 'updatetime' => $date]);
  185. break;
  186. case 2:
  187. $where = [['is_del', '=', 0], ['id', 'in', $param['ids']]];
  188. $temp = Db::name('customer_info')->field('id,companyNo')->where($where)->where('status', 1)->findOrEmpty();
  189. if (!empty($temp)) throw new Exception($temp['companyNo'] . '启用状态,不允许删除');
  190. $codes = Db::name('customer_info')->where($where)->column('companyNo');
  191. Db::name('customer_info')
  192. ->where($where)
  193. ->update(['is_del' => 1, 'updatetime' => $date]);
  194. break;
  195. case 3:
  196. $where = [['is_del', '=', 0], ['id', 'in', $param['ids']]];
  197. $codes = Db::name('supplier')->where($where)->column('code');
  198. Db::name('supplier')->where($where)->update(['is_del' => 1, 'updatetime' => $date]);
  199. break;
  200. }
  201. Db::name('headquarters')
  202. ->where('is_del', 0)
  203. ->whereIn('code', $codes)
  204. ->update([
  205. 'is_del' => 1,
  206. 'updater' => $param['updater'],
  207. 'updaterid' => $param['updaterid'],
  208. 'updatetime' => date('Y-m-d H:i:s')
  209. ]);
  210. Db::commit();
  211. return json_show(0, '删除成功');
  212. } catch (Exception $exception) {
  213. Db::rollback();
  214. return json_show(1005, '删除失败,' . $exception->getMessage());
  215. }
  216. }
  217. //启禁用
  218. public function status()
  219. {
  220. $param = $this->request->only(['id', 'type', 'status', 'updater', 'updaterid'], 'post', 'trim');
  221. $val = Validate::rule([
  222. 'id' => 'require|number|gt:0',
  223. 'type|类别' => 'require|number|in:1,2,3',
  224. 'status|状态' => 'require|number|in:0,1',
  225. 'updater|操作人' => 'require|max:255',
  226. 'updaterid|操作人id' => 'require|number|gt:0',
  227. ]);
  228. if (!$val->check($param)) return json_show(1004, $val->getError());
  229. Db::startTrans();
  230. try {
  231. $date = date('Y-m-d H:i:s');
  232. $code = '';
  233. switch ($param['type']) {
  234. case 1:
  235. $tmp = Db::name('business')
  236. ->field('id,companyNo code,status')
  237. ->where(['id' => $param['id'], 'is_del' => 0])
  238. ->findOrEmpty();
  239. if (empty($tmp)) throw new Exception('未找到对应数据');
  240. if ($tmp['status'] == $param['status']) throw new Exception('操作重复');
  241. Db::name('business')
  242. ->where(['id' => $param['id'], 'is_del' => 0])
  243. ->where('status', '<>', $param['status'])
  244. ->update([
  245. 'status' => $param['status'],
  246. 'updatetime' => $date
  247. ]);
  248. break;
  249. case 2:
  250. $tmp = Db::name('customer_info')
  251. ->field('id,status,companyNo code')
  252. ->where(['is_del' => 0, 'id' => $param['id']])
  253. ->findOrEmpty();
  254. if (empty($tmp)) throw new Exception('未找到对应数据');
  255. if ($tmp['status'] == $param['status']) throw new Exception('操作重复');
  256. Db::name('customer_info')
  257. ->where(['id' => $param['id'], 'is_del' => 0])
  258. ->where('status', '<>', $param['status'])
  259. ->update([
  260. 'status' => $param['status'],
  261. 'updatetime' => $date
  262. ]);
  263. break;
  264. case 3:
  265. $tmp = Db::name('supplier')
  266. ->where(['id' => $param['id'], 'is_del' => 0])
  267. ->field('id,code,status')
  268. ->findOrEmpty();
  269. if (empty($tmp)) throw new Exception('该供应商不存在');
  270. if ($tmp['status'] == $param['status']) throw new Exception('操作重复');
  271. Db::name('supplier')
  272. ->where(['id' => $param['id'], 'is_del' => 0])
  273. ->where('status', '<>', $param['status'])
  274. ->update([
  275. 'status' => $param['status'],
  276. 'updatetime' => $date
  277. ]);
  278. break;
  279. }
  280. Db::name('headquarters')
  281. ->where(['code' => $tmp['code'], 'is_del' => 0])
  282. ->where('status', '<>', $param['status'])
  283. ->update([
  284. 'status' => $param['status'],
  285. 'updater' => $param['updater'],
  286. 'updaterid' => $param['updaterid'],
  287. 'updatetime' => $date
  288. ]);
  289. Db::commit();
  290. return json_show(0, '操作成功');
  291. } catch (Exception $exception) {
  292. Db::rollback();
  293. return json_show(1005, '操作失败,' . $exception->getMessage());
  294. }
  295. }
  296. //获取指定编码和名称
  297. public function getCodeAndName()
  298. {
  299. $companyNo = $this->request->filter('trim')->post('code');
  300. $res_1 = Db::name('supplier')
  301. ->where('is_del', 0)
  302. ->whereIn('code', $companyNo)
  303. ->column('name', 'code');
  304. // $res_2 = Db::name('headquarters')
  305. // ->where('is_del', 0)
  306. // ->whereIn('relation_code', $companyNo)
  307. // ->column('name', 'relation_code');
  308. return json_show(0, '请求成功', $res_1);
  309. }
  310. //业务公司
  311. public function bGetList()
  312. {
  313. $param = $this->request->only([
  314. 'page' => 1,
  315. 'size' => 10,
  316. 'company' => '',
  317. 'status' => '',
  318. 'creater' => '',
  319. 'start' => '',
  320. 'end' => '',
  321. 'company_name' => '',
  322. ], 'post', 'trim');
  323. $where = [['a.is_del', "=", 0]];
  324. if ($param['company'] !== "") $where[] = ["a.company", "like", '%' . $param['company'] . '%'];
  325. if ($param['status'] !== "") $where[] = ["a.status", '=', $param['status']];
  326. if ($param['creater'] !== "") $where[] = ["a.creater", "like", '%' . $param['creater'] . '%'];
  327. if ($param['start'] !== "") $where[] = ["a.addtime", '>=', $param['start']];
  328. if ($param['end'] !== "") $where[] = ["a.addtime", '<=', $param['end'] . ' 23:59:59'];
  329. $count = Db::name('business')
  330. ->alias('a')
  331. ->where($where)
  332. ->count('a.id');
  333. $list = Db::name('business')
  334. ->alias('a')
  335. ->field(true)
  336. ->where($where)
  337. ->page($param['page'], $param['size'])
  338. ->order(['addtime' => 'desc', 'id' => 'desc'])
  339. ->select()
  340. ->toArray();
  341. foreach ($list as &$value) {
  342. $value['company_name'] = '';
  343. }
  344. return json_show("0", "获取成功", ['list' => $list, 'count' => $count]);
  345. }
  346. public function bCreate()
  347. {
  348. $param = $this->request->filter('trim')->post('');
  349. Db::startTrans();
  350. try {
  351. $tmp = Db::name('business')
  352. ->field('id')
  353. ->where(['company' => $param['company'], 'is_del' => 0])
  354. ->findOrEmpty();
  355. if (!empty($tmp)) throw new Exception('该公司名称已存在');
  356. Db::name('business')->insert($param);
  357. Db::name('headquarters')->insert([
  358. 'code' => $param['companyNo'],
  359. 'name' => $param['company'],
  360. 'type' => 1,
  361. 'invoice_title' => '',
  362. 'invoice_people' => '',
  363. 'invoice_addr' => $param['inv_addr'],
  364. 'invoice_mobile' => $param['mobile'],
  365. 'invoice_code' => $param['inv_code'],
  366. 'invoice_bank' => $param['inv_bank'],
  367. 'invoice_bankNo' => $param['inv_bankNo'],
  368. 'invoice_img' => $param['license_img'],
  369. 'remark' => '',
  370. 'status' => $param['status'],
  371. 'is_del' => $param['is_del'],
  372. 'creater' => $param['creater'],
  373. 'createrid' => $param['createrid'],
  374. 'addtime' => $param['addtime'],
  375. 'updater' => $param['creater'],
  376. 'updaterid' => $param['createrid'],
  377. 'updatetime' => $param['updatetime'],
  378. ]);
  379. Db::commit();
  380. $param['type']=1;
  381. Cache::store("redis")->handler()->lpush("companycopy",json_encode($param,JSON_UNESCAPED_UNICODE));
  382. return json_show(0, '添加成功');
  383. } catch (Exception $exception) {
  384. Db::rollback();
  385. return json_show(1003, $exception->getMessage());
  386. }
  387. }
  388. public function bInfo()
  389. {
  390. $companyNo = $this->request->post('companyNo', '', 'trim');
  391. if ($companyNo == "") return json_show(1004, "参数companyNo不能为空");
  392. $info = Db::name('business')
  393. ->alias('a')
  394. ->field('a.*,b.company_type')
  395. ->leftJoin('company_type b', 'b.id=a.type AND b.is_del=0')
  396. ->where(['a.companyNo' => $companyNo, 'a.is_del' => 0])
  397. ->findOrEmpty();
  398. if (empty($info)) return json_show(1002, "未找到数据");
  399. return json_show(0, '获取成功', $info);
  400. }
  401. public function bEdit()
  402. {
  403. $param = $this->request->filter('trim')->post('');
  404. Db::startTrans();
  405. try {
  406. $info = Db::name('business')
  407. ->field('id,companyNo,company,contactor,inv_code,license_img')
  408. ->where(['id' => $param['id'], 'is_del' => 0])
  409. ->findOrEmpty();
  410. if (empty($info)) throw new Exception('未找到数据');
  411. Db::name('business')
  412. ->where(['id' => $param['id'], 'is_del' => 0])
  413. ->update(array_merge($param, ['updatetime' => date("Y-m-d H:i:s")]));
  414. Db::name('headquarters')
  415. ->where(['code' => $info['companyNo'], 'is_del' => 0])
  416. ->update([
  417. 'invoice_addr' => $param['inv_addr'],
  418. 'invoice_mobile' => $param['invoice_mobile'],
  419. 'invoice_bank' => $param['inv_bank'],
  420. 'invoice_bankNo' => $param['inv_bankNo'],
  421. 'invoice_title' => $param['invoice_title'],
  422. 'updatetime' => date("Y-m-d H:i:s"),
  423. ]);
  424. Db::commit();
  425. $param['type']=1;
  426. Cache::store("redis")->handler()->lpush("companycopy",json_encode(array_merge($info,$param),
  427. JSON_UNESCAPED_UNICODE));
  428. return json_show(0, '修改成功');
  429. } catch (Exception $exception) {
  430. Db::rollback();
  431. return json_show(1003, $exception->getMessage());
  432. }
  433. }
  434. public function bTitle()
  435. {
  436. $param = $this->request->only(['company_type' => '', 'status' => ''], 'post', 'trim');
  437. $rs = Db::name('company_type')->where('is_del', 0);
  438. if ($param['company_type'] != '') $rs->whereLike('company_type', '%' . $param['company_type'] . '%');
  439. if ($param['status'] != '') $rs->where('status', $param['status']);
  440. $list = $rs->select()->toArray();
  441. return json_show(0, '获取成功', $list);
  442. }
  443. //供应商
  444. public function sGetList()
  445. {
  446. $param = $this->request->only(['page' => 1, 'size' => 10, 'name' => '', 'code' => '', 'creater' => '', 'person' => '', 'status' => '', 'ocr_status' => '', 'start' => '', 'end' => '', 'company_name' => '', 'is_platform' => '', 'more_code' => ''], 'post', 'trim');
  447. $where = [['s.is_del', "=", 0]];
  448. if ($param['name'] !== "") $where[] = ["s.name", "like", '%' . $param['name'] . '%'];
  449. if ($param['code'] !== "") $where[] = ["s.code", "like", '%' . $param['code'] . '%'];
  450. if ($param['more_code'] !== "") $where[] = ["s.code", "in", $param['more_code']];
  451. if ($param['creater'] !== "") $where[] = ["s.creater", "like", '%' . $param['creater'] . '%'];
  452. if ($param['person'] !== "") $where[] = ["s.person", "like", '%' . $param['person'] . '%'];
  453. if ($param['status'] !== "") $where[] = ["s.status", '=', $param['status']];
  454. if ($param['ocr_status'] !== "") $where[] = ["s.ocr_status", '=', $param['ocr_status']];
  455. if ($param['start'] !== "") $where[] = ["s.addtime", '>=', $param['start']];
  456. if ($param['end'] !== "") $where[] = ["s.addtime", '<=', $param['end'] . ' 23:59:59'];
  457. if ($param['is_platform'] !== "") $where[] = ["s.is_platform", '=', $param['is_platform']];
  458. // if ($param['company_name'] !== "") $where[] = ["s.createrid", 'in', $param['company_name']];
  459. $count = Db::name('supplier')
  460. ->alias('s')
  461. // ->leftJoin("depart_user u", "u.uid=s.createrid AND u.is_del=0")
  462. ->where($where)
  463. ->count('s.id');
  464. $list = Db::name('supplier')
  465. ->alias('s')
  466. ->field(true)
  467. // ->field('s.*,u.itemid')
  468. // ->leftJoin("depart_user u", "u.uid=s.createrid AND u.is_del=0")
  469. ->where($where)
  470. ->page($param['page'], $param['size'])
  471. ->order("addtime desc")
  472. ->select()
  473. ->toArray();
  474. // $all_codes = Db::name('supplier_contact')
  475. // ->whereIn('code', array_column($list, 'code'))
  476. // ->column("id,contactor,mobile", 'code');
  477. //获取开通账号的供应商
  478. // $account = checkHasAccountBySupplierNos(array_column($list,'code'));
  479. foreach ($list as &$value) {
  480. $value['company_name'] = '';
  481. $value['has_account'] = (AccountCompany::alias("a")
  482. ->leftJoin('account b', 'b.id=a.account_id')
  483. ->where([ ['a.is_del', '=', 0], ['a.status', '=', 1], ['b.status', '=', 1],['b.level', '=', 3], ['a.companyCode', '=', $value['code']]])
  484. ->findOrEmpty()->isEmpty())==False;
  485. }
  486. return json_show("0", "获取成功", ['list' => $list, 'count' => $count]);
  487. }
  488. public function sCreate()
  489. {
  490. $param = $this->request->only(['data', 'contact'], 'post', 'trim');
  491. $val = Validate::rule([
  492. 'data|供应商数据' => 'require|array',
  493. 'contact|联系人' => 'require|array',
  494. ]);
  495. if ($val->check($param) == false) return json_show(1004, $val->getError());
  496. Db::startTrans();
  497. try {
  498. $tmp = Db::name('supplier')
  499. ->field('id')
  500. ->where(['name' => $param['data']['name'], 'is_del' => 0])
  501. ->findOrEmpty();
  502. if (!empty($tmp)) throw new Exception('该供应商名称已存在');
  503. $id = Db::name('supplier')->insertGetId($param['data']);
  504. Db::name('supplier_contact')->insert($param['contact']);
  505. Db::name('headquarters')->insert([
  506. 'code' => $param['data']['code'],
  507. 'name' => $param['data']['name'],
  508. 'type' => 3,
  509. 'invoice_title' => '',
  510. 'invoice_people' => '',
  511. 'invoice_addr' => '',
  512. 'invoice_mobile' => $param['contact']['mobile'],
  513. 'invoice_code' => '',
  514. 'invoice_bank' => '',
  515. 'invoice_bankNo' => '',
  516. 'invoice_img' => $param['data']['license_img'],
  517. 'remark' => $param['data']['remark'],
  518. 'status' => $param['data']['status'],
  519. 'is_del' => $param['data']['is_del'],
  520. 'creater' => $param['data']['creater'],
  521. 'createrid' => $param['data']['createrid'],
  522. 'addtime' => $param['data']['addtime'],
  523. 'updater' => $param['data']['creater'],
  524. 'updaterid' => $param['data']['createrid'],
  525. 'updatetime' => $param['data']['updatetime'],
  526. ]);
  527. Db::commit();
  528. $param['data']['type']=3;
  529. Cache::store("redis")->handler()->lpush("companycopy",json_encode($param['data'],JSON_UNESCAPED_UNICODE));
  530. return json_show(0, '添加成功', ['id' => $id]);
  531. } catch (Exception $exception) {
  532. Db::rollback();
  533. return json_show(1003, $exception->getMessage());
  534. }
  535. }
  536. public function sInfo()
  537. {
  538. $code = $this->request->post('code', '', 'trim');
  539. if ($code == "") return json_show(1004, "参数code不能为空");
  540. $info = Db::name('supplier')
  541. ->alias('a')
  542. ->field('a.*,b.contactor,b.mobile,b.position,b.email,b.telephone')
  543. ->leftJoin('supplier_contact b', 'b.code=a.code AND b.is_del=0')
  544. ->where(['a.code' => $code, 'a.is_del' => 0])
  545. ->findOrEmpty();
  546. if (empty($info)) return json_show(1002, "未找到供应商数据");
  547. return json_show(0, '获取成功', $info);
  548. }
  549. public function sEdit()
  550. {
  551. $param = $this->request->only(['data', 'contact'], 'post', 'trim');
  552. $val = Validate::rule([
  553. 'data|供应商数据' => 'require|array',
  554. 'contact|联系人' => 'require|array',
  555. ]);
  556. if ($val->check($param) == false) return json_show(1004, $val->getError());
  557. Db::startTrans();
  558. try {
  559. $tmp = Db::name('supplier')
  560. ->field('id')
  561. ->where(['name' => $param['data']['name'], 'is_del' => 0])
  562. ->where('id', '<>', $param['data']['id'])
  563. ->findOrEmpty();
  564. if (!empty($tmp)) throw new Exception('该供应商名称已存在');
  565. $id = Db::name('supplier')
  566. ->where(['id' => $param['data']['id'], 'is_del' => 0])
  567. ->strict(false)
  568. ->update($param['data']);
  569. $tmp = Db::name('supplier_contact')
  570. ->field('id')
  571. ->where(['code' => $param['contact']['code'], 'is_del' => 0])
  572. ->findOrEmpty();
  573. if (empty($tmp)) Db::name('supplier_contact')->insert(array_merge($param['contact'], ['addtime' => $param['contact']['updatetime']]));
  574. else Db::name('supplier_contact')->where(['id' => $tmp['id'], 'is_del' => 0])->update($param['contact']);
  575. Db::name('headquarters')
  576. ->where(['code' => $param['contact']['code'], 'is_del' => 0])
  577. ->update([
  578. 'name' => $param['data']['name'],
  579. 'type' => 3,
  580. 'invoice_title' => '',
  581. 'invoice_people' => '',
  582. 'invoice_addr' => '',
  583. 'invoice_mobile' => $param['contact']['mobile'],
  584. 'invoice_code' => '',
  585. 'invoice_bank' => '',
  586. 'invoice_bankNo' => '',
  587. 'invoice_img' => $param['data']['license_img'],
  588. 'remark' => $param['data']['remark'],
  589. 'is_del' => $param['data']['is_del'],
  590. 'updater' => $param['data']['updater'],
  591. 'updaterid' => $param['data']['updaterid'],
  592. 'updatetime' => date("Y-m-d H:i:s"),
  593. ]);
  594. $this->checkSupplier($param['data'],$param['contact']);
  595. Db::commit();
  596. $param['data']['type']=3;
  597. Cache::store("redis")->handler()->lpush("companycopy",json_encode($param['data'],JSON_UNESCAPED_UNICODE));
  598. return json_show(0, '修改成功', ['id' => $id]);
  599. } catch (Exception $exception) {
  600. Db::rollback();
  601. return json_show(1003, $exception->getMessage());
  602. }
  603. }
  604. //客户
  605. public function cInfo()
  606. {
  607. $companyNo = $this->request->post('companyNo', '', 'trim');
  608. $info = Db::name('customer_info')
  609. ->where(['is_del' => 0, 'companyNo' => $companyNo])
  610. ->field(true)
  611. ->findOrEmpty();
  612. $info['member'] = Db::name("customer_member")
  613. ->where(['companyNo' => $companyNo, "is_del" => 0])
  614. ->order('id')
  615. ->select()
  616. ->toArray();
  617. return json_show(0, "获取成功", $info);
  618. }
  619. public function cTitle()
  620. {
  621. $param = $this->request->only([
  622. 'page' => 1,
  623. 'size' => 10,
  624. 'companyNo' => '',
  625. 'companyName' => '',
  626. 'itemid' => '',
  627. ], 'post', 'trim');
  628. $where [] = ['is_del', "=", 0];
  629. if ($param['companyNo'] != '') $where[] = ['companyNo', 'like', '%' . $param['companyNo'] . '%'];
  630. if ($param['companyName'] != '') $where[] = ['companyName', 'like', '%' . $param['companyName'] . '%'];
  631. if ($param['itemid'] != '') $where[] = ['itemid', '=', $param['itemid']];
  632. $count = Db::name('customer_info')
  633. ->where($where)
  634. ->count('id');
  635. $item = Db::name('customer_info')
  636. ->where($where)
  637. ->field("id,companyNo,companyName,area,LENGTH(companyName) as weight,status")
  638. ->order(['weight' => 'asc', 'id' => 'desc'])
  639. ->page($param['page'], $param['size'])
  640. ->select()
  641. ->toArray();
  642. return json_show(0, "获取成功", ['item' => $item, 'count' => $count]);
  643. }
  644. public function cCreate()
  645. {
  646. $param = $this->request->only([
  647. 'companyName',
  648. 'parent' => 0,
  649. 'customer_member',
  650. 'uid',
  651. 'uname',
  652. 'branch',
  653. 'middle',
  654. 'area',
  655. ], 'post', 'trim');
  656. $val = Validate::rule([
  657. 'companyName|客户名称' => 'require',
  658. 'customer_member|联系方式' => 'require|array|max:100',
  659. 'uid' => 'require|number|gt:0',
  660. 'uname|创建人' => 'require',
  661. 'branch|省级' => 'require',
  662. 'middle|市级' => 'require',
  663. 'area|区域' => 'require',
  664. ]);
  665. if ($val->check($param) == false) return json_show(1004, $val->getError());
  666. $companyNo = makeNo("KH");
  667. $rename = Db::name('customer_org1')
  668. ->field('id')
  669. ->where(['is_del' => 0, 'id' => $param['parent']])
  670. ->findOrEmpty();
  671. $item = Db::name('customer_info')
  672. ->field('id')
  673. ->where(['itemid' => $rename['id'] ?? 0, 'companyName' => $param['companyName'], 'is_del' => 0])
  674. ->findOrEmpty();
  675. if (!empty($item)) return json_show(1002, "公司名称已存在");
  676. $createrid = $param['uid'];//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  677. $creater = $param['uname'];//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  678. Db::startTrans();
  679. try {
  680. $date = date('Y-m-d H:i:s');
  681. $data = [
  682. "companyNo" => $companyNo,
  683. "companyName" => $param['companyName'],
  684. "parent" => $param['parent'],
  685. "itemid" => $param['parent'],
  686. "area" =>$param['area'],
  687. "status" => 0,
  688. "branch" =>$param['branch'],
  689. "middle" =>$param['middle'],
  690. "is_del" => 0,
  691. "createrid" => $createrid,
  692. "creater" => $creater,
  693. "addtime" => $date,
  694. "updatetime" => $date,
  695. ];
  696. $datainfo = Db::name('customer_info')->insert($data);
  697. if ($datainfo) {
  698. $var = [];
  699. foreach ($param['customer_member'] as $value) {
  700. $var[] = [
  701. 'commobile' => $value['commobile'] ?? '',
  702. 'comtel' => '',
  703. 'contactor' => $value['contactor'] ?? '',
  704. 'position' => $value['position'] ?? '',
  705. 'wxaccount' => $value['wxaccount'] ?? '',
  706. 'qqaccount' => $value['qqaccount'] ?? '',
  707. 'email' => $value['email'] ?? '',
  708. 'comdepart' => $value['comdepart'] ?? '',
  709. 'status' => $value['status'] ?? '',
  710. 'createrid' => $createrid,
  711. 'creater' => $creater,
  712. 'companyNo' => $companyNo,
  713. 'is_del' => 0,
  714. 'addtime' => $date,
  715. 'updatetime' => $date,
  716. ];
  717. }
  718. $vp = Db::name('customer_member')->insertAll($var);
  719. if ($vp == "") throw new Exception('新建联系人失败');
  720. //汇总表
  721. Db::name('headquarters')
  722. ->insert([
  723. 'code' => $companyNo,
  724. 'name' => $param['companyName'],
  725. 'type' => 2,
  726. 'creater' => $param['uname'],
  727. 'createrid' => $param['uid'],
  728. "addtime" => $date,
  729. 'updater' => $param['uname'],
  730. 'updaterid' => $param['uid'],
  731. "updatetime" => $date,
  732. ]);
  733. Db::commit();
  734. $data['type']=2;
  735. Cache::store("redis")->handler()->lpush("companycopy",json_encode($data,JSON_UNESCAPED_UNICODE));
  736. return json_show(0, "新建成功");
  737. } else throw new Exception('新建失败');
  738. } catch (Exception $e) {
  739. Db::rollback();
  740. return json_show(1005, $e->getMessage());
  741. }
  742. }
  743. public function cList()
  744. {
  745. $param = $this->request->only(['page' => 1, 'size' => 10, 'companyName' => '', 'status' => '', 'creater' => '', 'start' => '', 'end' => ''], 'post', 'trim');
  746. $where = [["a.is_del", "=", 0]];
  747. if ($param['companyName'] != "") $where[] = ['b.companyName', "like", '%' . $param['companyName'] . '%'];
  748. if ($param['status'] !== "") $where[] = ['status', "=", $param['status']];
  749. if ($param['creater'] != "") $where[] = ['a.creater', "like", '%' . $param['creater'] . '%'];
  750. if ($param['start'] !== "") $where[] = ['a.addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))];
  751. if ($param['end'] !== "") $where[] = ['a.addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
  752. $count = Db::name('customer_member')
  753. ->alias('a')
  754. ->leftJoin('customer_info b', "b.companyNo=a.companyNo")
  755. ->where($where)
  756. ->count('a.id');
  757. $total = ceil($count / $param['size']);
  758. $page = $param['page'] >= $total ? $total : $param['page'];
  759. $list = Db::name('customer_member')
  760. ->alias('a')
  761. ->leftJoin('customer_info b', "b.companyNo=a.companyNo")
  762. ->where($where)
  763. ->page($page, $param['size'])
  764. ->order("addtime desc")
  765. ->field("a.*,b.companyName,b.parent,b.area")
  766. ->select()
  767. ->toArray();
  768. return json_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  769. }
  770. public function cEdit()
  771. {
  772. $param = $this->request->only([
  773. 'id',
  774. 'companyName',
  775. 'parent',
  776. 'customer_member',
  777. 'uid',
  778. 'uname',
  779. 'branch',
  780. 'middle',
  781. 'area',
  782. ], 'post', 'trim');
  783. $val = Validate::rule([
  784. 'id' => 'require|number|gt:0',
  785. 'companyName|客户名称' => 'require',
  786. 'parent' => 'require',
  787. 'customer_member|联系方式' => 'require|array|max:100',
  788. 'uid' => 'require|number|gt:0',
  789. 'uname|修改人' => 'require',
  790. 'branch|省级'=> 'require',
  791. 'middle|市级'=> 'require',
  792. 'area|区域'=> 'require',
  793. ]);
  794. if ($val->check($param) == false) return json_show(1004, $val->getError());
  795. $idinfo = Db::name('customer_info')
  796. ->field('id,status,companyNo')
  797. ->where(['id' => $param['id'], 'is_del' => 0])
  798. ->findOrEmpty();
  799. if (empty($idinfo)) return json_show(1004, "未找到数据");
  800. if ($idinfo['status'] == 1) return json_show(1002, "状态是启用状态,无法编辑");
  801. $rename = Db::name('customer_org1')
  802. ->where(['is_del' => 0, 'id' => $param['parent']])
  803. ->field('id')
  804. ->findOrEmpty();
  805. $item = Db::name('customer_info')
  806. ->field('id')
  807. ->where(['itemid' => $rename['id'] ?? 0, 'companyName' => $param['companyName'], 'is_del' => 0])
  808. ->where('id', '<>', $param['id'])
  809. ->findOrEmpty();
  810. if (!empty($item)) return json_show(1002, "公司名称已存在");
  811. $createrid = $param['uid'];//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  812. $creater = $param['uname'];//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  813. Db::startTrans();
  814. try {
  815. $date = date('Y-m-d H:i:s');
  816. $data = [
  817. "id" => $param['id'],
  818. "companyName" => $param['companyName'],
  819. "area" =>$param['area'],
  820. "branch" =>$param['branch'],
  821. "middle" =>$param['middle'],
  822. "parent" => $param['parent'],
  823. "updatetime" => $date,
  824. ];
  825. $datainfo = Db::name('customer_info')->save($data);
  826. if ($datainfo) {
  827. foreach ($param['customer_member'] as $value) {
  828. $item = [];
  829. $item['commobile'] = isset($value['commobile']) ? $value['commobile'] : "";
  830. $item['comtel'] = "";
  831. isset($value['id']) && $value['id'] !== "" ? $item['id'] = $value['id'] : '';
  832. $item['contactor'] = isset($value['contactor']) ? $value['contactor'] : "";
  833. $item['position'] = isset($value['position']) ? $value['position'] : "";
  834. $item['wxaccount'] = isset($value['wxaccount']) ? $value['wxaccount'] : "";
  835. $item['qqaccount'] = isset($value['qqaccount']) ? $value['qqaccount'] : "";
  836. $item['email'] = isset($value['email']) ? $value['email'] : "";
  837. $item['comdepart'] = isset($value['comdepart']) ? $value['comdepart'] : "";
  838. $item['status'] = $value['status'];
  839. $item['createrid'] = $createrid;
  840. $item['creater'] = $creater;
  841. $item['companyNo'] = isset($idinfo['companyNo']) ? $idinfo['companyNo'] : "";
  842. $item['is_del'] = 0;
  843. $item['addtime'] = $date;
  844. $item['updatetime'] = $date;
  845. $vp = Db::name('customer_member')->save($item);
  846. if ($vp == false) throw new Exception('更新失败');
  847. }
  848. //更新汇总表
  849. Db::name('headquarters')
  850. ->where(['is_del' => 0, 'type' => 2, 'code' => $idinfo['companyNo']])
  851. ->update([
  852. 'name' => $param['companyName'],
  853. 'updater' => $param['uname'],
  854. 'updaterid' => $param['uid'],
  855. "updatetime" => $date,
  856. ]);
  857. Db::commit();
  858. return json_show(0, "更新成功");
  859. } else throw new Exception("更新失败");
  860. } catch (Exception $e) {
  861. Db::rollback();
  862. return json_show(1005, $e->getMessage());
  863. }
  864. }
  865. //供应商升级成业务公司
  866. public function supplerUpgrade()
  867. {
  868. $post = $this->request->only(['code', 'inv_bank', 'inv_bankNo', 'inv_addr', 'invoice_mobile', 'uid', 'uname', 'invoice_title'], 'post', 'trim');
  869. $val = Validate::rule([
  870. 'code|供应商编码' => 'require',
  871. 'inv_bank|银行名称' => 'require|max:255',
  872. 'inv_bankNo|银行卡号' => 'require|number',
  873. 'inv_addr|联系地址' => 'require|max:255',
  874. 'invoice_mobile' => 'require',
  875. 'invoice_title|公司抬头' => 'require',
  876. ]);
  877. if ($val->check($post) == false) return json_show(1004, $val->getError());
  878. $res = Db::name('supplier')
  879. ->alias('a')
  880. ->field('a.id,a.status,a.nature,b.contactor,b.mobile,a.name,a.code,a.registercode,a.legaler,a.registertime,a.addr,a.scope,a.license_img,a.is_upgrade')
  881. ->leftJoin('supplier_contact b', 'b.code=a.code')
  882. ->where(['a.code' => $post['code'], 'a.is_del' => 0])
  883. ->findOrEmpty();
  884. if (empty($res)) return json_show(1004, '该供应商不存在');
  885. if ($res['status'] != 1) return json_show(1004, '该供应商已禁用');
  886. if ($res['is_upgrade'] == 1) return json_show(1004, '不能重复升级');
  887. $temp = Db::name('company_type')
  888. ->field('id')
  889. ->where(['company_type' => $res['nature'], 'is_del' => 0])
  890. ->findOrEmpty();
  891. // if (empty($temp)) return json_show(1004, '对应公司类型不存在');
  892. Db::startTrans();
  893. try {
  894. $date = date('Y-m-d H:i:s');
  895. $business_code = makeNo('GS');
  896. //业务公司列表
  897. Db::name('business')
  898. ->insert([
  899. 'company' => $res['name'],
  900. 'companyNo' => $business_code,
  901. 'inv_code' => $res['registercode'],
  902. 'company_type' => $res['nature'],
  903. 'type' => $temp['id'] ?? 0,
  904. 'creater' => $post['uname'],
  905. 'createrid' => $post['uid'],
  906. 'inv_legaler' => $res['legaler'],
  907. 'inv_time' => $res['registertime'],
  908. 'inv_addr' => $post['inv_addr'],
  909. 'inv_bank' => $post['inv_bank'],
  910. 'inv_bankNo' => $post['inv_bankNo'],
  911. 'contactor' => $res['contactor'],
  912. 'mobile' => $res['mobile'],
  913. 'addr' => $res['addr'],
  914. 'inv_scope' => $res['scope'],
  915. 'license_img' => $res['license_img'],
  916. 'invoice_title' => $post['invoice_title'],
  917. 'invoice_mobile' => $post['invoice_mobile'],
  918. 'status' => 1,
  919. 'is_del' => 0,
  920. 'addtime' => $date,
  921. 'updatetime' => $date,
  922. ]);
  923. $temp_supplier = Db::name('headquarters')
  924. ->where(['code' => $post['code'], 'type' => 3])
  925. ->findOrEmpty();
  926. //汇总表
  927. Db::name('headquarters')
  928. ->where(['code' => $post['code'], 'type' => 3])
  929. ->update([
  930. 'relation_code' => $business_code,
  931. 'updater' => $post['uname'],
  932. 'updaterid' => $post['uid'],
  933. 'updatetime' => $date,
  934. ]);
  935. Db::name('headquarters')
  936. ->insert(array_merge($temp_supplier, [
  937. 'id' => null,
  938. 'code' => $business_code,
  939. 'type' => 1,//业务公司
  940. 'relation_code' => $post['code']
  941. ]));
  942. //供应商
  943. Db::name('supplier')
  944. ->where(['code' => $post['code'], 'is_upgrade' => 0, 'is_del' => 0])
  945. ->update(['is_upgrade' => 1, 'updatetime' => $date]);
  946. //账号与公司的关联关系
  947. Db::name('account_company')
  948. ->insert([
  949. 'account_id' => $post['uid'],
  950. 'companyCode' => $business_code,
  951. 'companyName' => $res['name'],
  952. 'company_type' => 2,
  953. 'status' => 1,
  954. 'is_del' => 0,
  955. 'addtime' => $date,
  956. 'updatetime' => $date,
  957. ]);
  958. Db::commit();
  959. return json_show(0, '升级成功');
  960. } catch (Exception $exception) {
  961. Db::rollback();
  962. return json_show(1004, '升级失败,' . $exception->getMessage());
  963. }
  964. }
  965. //获取业务公司列表(为了采销临时脚本同步数据到结算平台使用,正式上线要删除)
  966. public function getBusinessListTmp()
  967. {
  968. $where = $this->request->filter('trim')->post('where', []);
  969. $list = Db::name('business')
  970. ->alias('a')
  971. ->field('a.*,b.code as supplierNo')
  972. ->leftJoin('headquarters b', 'b.relation_code=a.companyNo')
  973. ->where($where)
  974. ->select()
  975. ->toArray();
  976. return json_show(0, '获取成功', $list);
  977. }
  978. private function checkSupplier($supplier,$canact){
  979. $hquest = Db::name("headquarters")->where(["code"=>$supplier["code"],"is_del"=>0])->findOrEmpty();
  980. if(empty($hquest)) throw new Exception("未找到供应商关联数据");
  981. if($hquest['relation_code']!='' && $hquest['type']==3){
  982. $comp = Db::name('headquarters')->where(['code'=>$hquest['relation_code'],'is_del'=>0])->findOrEmpty();
  983. if(empty($comp)) throw new Exception('未找到供应商关联业务公司数据');
  984. $business = Db::name("business")->where(['companyNo'=>$hquest['relation_code'],'is_del'=>0])->findOrEmpty();
  985. if(empty($business)) throw new Exception('未找到供应商关联业务公司数据');
  986. $comp['name'] = $supplier['name'];
  987. !isset($supplier['legaler'])?:$comp['invoice_people'] = $supplier['legaler'];
  988. !isset($supplier['registercode'])?:$comp['invoice_code'] = $supplier['registercode'];
  989. !isset($supplier['license_img'])?:$comp['invoice_img'] = $supplier['license_img'];
  990. $comp['updatetime'] = date("Y-m-d H:i:s");
  991. $ip = Db::name('headquarters')->save($comp);
  992. if($ip==false) throw new Exception('供应商关联业务公司数据更新失败');
  993. $business['company'] =$supplier['name'];
  994. !isset($supplier['registercode'])?:$business['inv_code'] =$supplier['registercode'];
  995. !isset($supplier['legaler'])?:$business['inv_legaler'] =$supplier['legaler'];
  996. !isset($supplier['registertime'])?:$business['inv_time'] =$supplier['registertime'];
  997. !isset($supplier['addr'])?:$business['addr'] =$supplier['addr'];
  998. !isset($canact['contactor'])?:$business['contactor'] =$canact['contactor'];
  999. !isset($canact['mobile'])?:$business['mobile'] =$canact['mobile'];
  1000. !isset($supplier['scope'])?:$business['inv_scope'] =$supplier['scope'];
  1001. $business['license_img'] =$supplier['license_img'];
  1002. $business['creater'] =$supplier['updater'];
  1003. $business['createrid'] =$supplier['updaterid'];
  1004. $business['updatetime'] = date('Y-m-d H:i:s');
  1005. $bp = Db::name('business')->save($business);
  1006. if($bp==false) throw new Exception('业务公司数据更新失败');
  1007. $business['type']=1;
  1008. Cache::store('redis')->handler()->lpush('companycopy',json_encode($business,JSON_UNESCAPED_UNICODE));
  1009. }
  1010. }
  1011. }