Api.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\contract\controller;
  15. use app\api\BaseController;
  16. use app\contract\model\Contract;
  17. use app\contract\model\Purchase;
  18. use app\contract\model\SupplierContact;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Api extends BaseController
  22. {
  23. //获取销售合同协议
  24. public function get_contract()
  25. {
  26. $param = get_params();
  27. $uid = $this->uid;
  28. $where = array();
  29. $whereOr = array();
  30. if (!empty($param['keywords'])) {
  31. $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
  32. }
  33. $where[] = ['delete_time', '=', 0];
  34. $where[] = ['check_status', '=', 2];
  35. //是否是合同管理员
  36. $auth = isAuth($uid,'contract_admin','conf_1');
  37. if($auth == 0){
  38. $whereOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
  39. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  40. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  41. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  42. $dids_a = get_leader_departments($uid);
  43. $dids_b = get_role_departments($uid);
  44. $dids = array_merge($dids_a, $dids_b);
  45. if(!empty($dids)){
  46. $whereOr[] = ['did','in',$dids];
  47. }
  48. }
  49. $model = new Contract();
  50. $list = $model->datalist($param,$where,$whereOr);
  51. return table_assign(0, '', $list);
  52. }
  53. //销售合同归档操作
  54. public function contract_archive()
  55. {
  56. if (request()->isPost()) {
  57. $param = get_params();
  58. $tips='操作成功,合同已转入到归档合同列表';
  59. if($param['archive_status'] == 1){
  60. $param['archive_uid'] = $this->uid;
  61. $param['archive_time'] = time();
  62. }
  63. else{
  64. $param['archive_uid'] = 0;
  65. $param['archive_time'] = 0;
  66. $tips='操作成功,合同已从归档合同列表转出';
  67. }
  68. if (Db::name('Contract')->strict(false)->update($param) !== false) {
  69. return to_assign(0, $tips);
  70. } else {
  71. return to_assign(1, "操作失败");
  72. }
  73. } else {
  74. return to_assign(1, "错误的请求");
  75. }
  76. }
  77. //销售合同中止等操作
  78. public function contract_stop()
  79. {
  80. if (request()->isPost()) {
  81. $param = get_params();
  82. $tips='操作成功,合同已转入到中止合同列表';
  83. if($param['stop_status'] == 1){
  84. $param['stop_uid'] = $this->uid;
  85. $param['stop_time'] = time();
  86. }
  87. else{
  88. $param['stop_uid'] = 0;
  89. $param['stop_time'] = 0;
  90. $tips='操作成功,合同已从中止合同列表转出';
  91. }
  92. if (Db::name('Contract')->strict(false)->update($param) !== false) {
  93. return to_assign(0, $tips);
  94. } else {
  95. return to_assign(1, "操作失败");
  96. }
  97. } else {
  98. return to_assign(1, "错误的请求");
  99. }
  100. }
  101. //销售合同作废等操作
  102. public function contract_tovoid()
  103. {
  104. if (request()->isPost()) {
  105. $param = get_params();
  106. $tips='操作成功,合同已转入到作废合同列表';
  107. if($param['void_status'] == 1){
  108. $param['void_uid'] = $this->uid;
  109. $param['void_time'] = time();
  110. }
  111. else{
  112. $param['void_uid'] = 0;
  113. $param['void_time'] = 0;
  114. $tips='操作成功,合同已从作废合同列表转出';
  115. }
  116. if (Db::name('Contract')->strict(false)->update($param) !== false) {
  117. return to_assign(0, $tips);
  118. } else {
  119. return to_assign(1, "操作失败");
  120. }
  121. } else {
  122. return to_assign(1, "错误的请求");
  123. }
  124. }
  125. //获取产品分类数据
  126. public function get_productcate_tree()
  127. {
  128. $cate = get_base_data('ProductCate');
  129. $list = get_tree($cate, 0, 2);
  130. $data['trees'] = $list;
  131. return json($data);
  132. }
  133. //获取销售产品列表
  134. public function get_product()
  135. {
  136. $param = get_params();
  137. $where = array();
  138. if (!empty($param['keywords'])) {
  139. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  140. }
  141. $where[] = ['delete_time', '=', 0];
  142. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  143. $list = Db::name('Product')->field('id,title,sale_price,purchase_price,base_price,unit,specs')->order('id asc')->where($where)->paginate(['list_rows'=> $rows]);
  144. table_assign(0, '', $list);
  145. }
  146. //更新合同电子文件
  147. public function contract_seal_ids()
  148. {
  149. if (request()->isPost()) {
  150. $param = get_params();
  151. if (Db::name('Contract')->strict(false)->update($param) !== false) {
  152. return to_assign();
  153. } else {
  154. return to_assign(1, "操作失败");
  155. }
  156. } else {
  157. return to_assign(1, "错误的请求");
  158. }
  159. }
  160. /*
  161. -------------------------------------------------分割线---------------------------------------------------------
  162. */
  163. //获取采购合同协议
  164. public function get_purchase()
  165. {
  166. $param = get_params();
  167. $uid = $this->uid;
  168. $where = array();
  169. $whereOr = array();
  170. if (!empty($param['keywords'])) {
  171. $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
  172. }
  173. $where[] = ['delete_time', '=', 0];
  174. $where[] = ['check_status', '=', 2];
  175. $auth = isAuth($uid,'contract_admin','conf_1');
  176. if($auth == 0){
  177. $whereOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
  178. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  179. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  180. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  181. $dids_a = get_leader_departments($uid);
  182. $dids_b = get_role_departments($uid);
  183. $dids = array_merge($dids_a, $dids_b);
  184. if(!empty($dids)){
  185. $whereOr[] = ['did','in',$dids];
  186. }
  187. }
  188. $model = new Purchase();
  189. $list = $model->datalist($param,$where,$whereOr);
  190. return table_assign(0, '', $list);
  191. }
  192. //采购合同归档操作
  193. public function purchase_archive()
  194. {
  195. if (request()->isPost()) {
  196. $param = get_params();
  197. $tips='操作成功,合同已转入到归档合同列表';
  198. if($param['archive_status'] == 1){
  199. $param['archive_uid'] = $this->uid;
  200. $param['archive_time'] = time();
  201. }
  202. else{
  203. $param['archive_uid'] = 0;
  204. $param['archive_time'] = 0;
  205. $tips='操作成功,合同已从归档合同列表转出';
  206. }
  207. if (Db::name('Purchase')->strict(false)->update($param) !== false) {
  208. return to_assign(0, $tips);
  209. } else {
  210. return to_assign(1, "操作失败");
  211. }
  212. } else {
  213. return to_assign(1, "错误的请求");
  214. }
  215. }
  216. //采购合同中止等操作
  217. public function purchase_stop()
  218. {
  219. if (request()->isPost()) {
  220. $param = get_params();
  221. $tips='操作成功,合同已转入到中止合同列表';
  222. if($param['stop_status'] == 1){
  223. $param['stop_uid'] = $this->uid;
  224. $param['stop_time'] = time();
  225. }
  226. else{
  227. $param['stop_uid'] = 0;
  228. $param['stop_time'] = 0;
  229. $tips='操作成功,合同已从中止合同列表转出';
  230. }
  231. if (Db::name('Purchase')->strict(false)->update($param) !== false) {
  232. return to_assign(0, $tips);
  233. } else {
  234. return to_assign(1, "操作失败");
  235. }
  236. } else {
  237. return to_assign(1, "错误的请求");
  238. }
  239. }
  240. //采购合同作废等操作
  241. public function purchase_tovoid()
  242. {
  243. if (request()->isPost()) {
  244. $param = get_params();
  245. $tips='操作成功,合同已转入到作废合同列表';
  246. if($param['void_status'] == 1){
  247. $param['void_uid'] = $this->uid;
  248. $param['void_time'] = time();
  249. }
  250. else{
  251. $param['void_uid'] = 0;
  252. $param['void_time'] = 0;
  253. $tips='操作成功,合同已从作废合同列表转出';
  254. }
  255. if (Db::name('Purchase')->strict(false)->update($param) !== false) {
  256. return to_assign(0, $tips);
  257. } else {
  258. return to_assign(1, "操作失败");
  259. }
  260. } else {
  261. return to_assign(1, "错误的请求");
  262. }
  263. }
  264. //获取采购品分类数据
  265. public function get_purchasedcate_tree()
  266. {
  267. $cate = get_base_data('PurchasedCate');
  268. $list = get_tree($cate, 0, 2);
  269. $data['trees'] = $list;
  270. return json($data);
  271. }
  272. //获取供应商列表
  273. public function get_supplier()
  274. {
  275. $param = get_params();
  276. $where = array();
  277. if (!empty($param['keywords'])) {
  278. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  279. }
  280. $where[] = ['delete_time', '=', 0];
  281. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  282. $list = Db::name('Supplier')->field('id,title,address')->order('id asc')->where($where)->paginate(['list_rows'=> $rows])->each(function($item, $key){
  283. $contact = Db::name('SupplierContact')->where(['sid'=>$item['id'],'is_default'=>1])->find();
  284. if(!empty($contact)){
  285. $item['contact_name'] = $contact['name'];
  286. $item['contact_mobile'] = $contact['mobile'];
  287. }
  288. else{
  289. $item['contact_name'] = '';
  290. $item['contact_mobile'] = '';
  291. }
  292. return $item;
  293. });
  294. table_assign(0, '', $list);
  295. }
  296. //获取采购物品列表
  297. public function get_purchased()
  298. {
  299. $param = get_params();
  300. $where = array();
  301. if (!empty($param['keywords'])) {
  302. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  303. }
  304. $where[] = ['delete_time', '=', 0];
  305. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  306. $list = Db::name('Purchased')->field('id,title,purchase_price,sale_price,unit,specs')->order('id asc')->where($where)->paginate(['list_rows'=> $rows]);
  307. table_assign(0, '', $list);
  308. }
  309. //获取供应商联系人数据
  310. public function get_supplier_contact()
  311. {
  312. $param = get_params();
  313. $where = array();
  314. $where[] = ['delete_time', '=', 0];
  315. $where[] = ['sid', '=', $param['supplier_id']];
  316. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  317. $content = SupplierContact::where($where)
  318. ->order('create_time desc')
  319. ->paginate(['list_rows'=> $rows])
  320. ->each(function ($item, $key) {
  321. $item->admin_name = Db::name('Admin')->where(['id' => $item->admin_id])->value('name');
  322. $item->create_time = date('Y-m-d H:i:s', (int) $item->create_time);
  323. });
  324. return table_assign(0, '', $content);
  325. }
  326. //设置供应商联系人
  327. public function set_supplier_contact()
  328. {
  329. if (request()->isAjax()) {
  330. $param = get_params();
  331. $detail= SupplierContact::where(['id' => $param['id']])->find();
  332. SupplierContact::where(['sid' => $detail['sid']])->strict(false)->field(true)->update(['is_default'=>0]);
  333. $res = SupplierContact::where(['id' => $param['id']])->update(['is_default'=>1]);
  334. if ($res) {
  335. add_log('edit', $param['id'], $param,'供应商联系人');
  336. return to_assign();
  337. } else {
  338. return to_assign(1, '操作失败');
  339. }
  340. } else {
  341. return to_assign(1, '参数错误');
  342. }
  343. }
  344. //更新合同电子文件
  345. public function purchase_seal_ids()
  346. {
  347. if (request()->isPost()) {
  348. $param = get_params();
  349. if (Db::name('Purchase')->strict(false)->update($param) !== false) {
  350. return to_assign();
  351. } else {
  352. return to_assign(1, "操作失败");
  353. }
  354. } else {
  355. return to_assign(1, "错误的请求");
  356. }
  357. }
  358. }