LargeWasteRewardPunish.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\db;
  5. use think\Request;
  6. use function fast\e;
  7. /**
  8. * 工序大废品惩奖记录接口
  9. */
  10. class LargeWasteRewardPunish extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 首页
  16. *
  17. */
  18. public function index()
  19. {
  20. $this->success('请求成功');
  21. }
  22. /**
  23. * 获取工序大废品惩奖侧边栏
  24. * @ApiMethod (GET)
  25. */
  26. public function getTab()
  27. {
  28. //get请求
  29. if(!$this->request->isGet()){
  30. $this->error('请求方式错误');
  31. }
  32. $rows = db()->table('db_大废品')
  33. ->field('DISTINCT(LEFT(sys_rq, 7)) AS mouth,LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  34. ->group('date')
  35. ->order('UniqId desc')
  36. ->limit(40)
  37. ->select();
  38. $list = [];
  39. foreach($rows as $key=>$value){
  40. if (!isset($list[$value['mouth']])){
  41. $list[$value['mouth']] = [];
  42. }
  43. $arr['date'] = str_replace('-', '.', $rows[$key]['date']);
  44. $arr['counts'] = $rows[$key]['counts'];
  45. array_push($list[$value['mouth']],$arr);
  46. // $list[$value['mouth']]['date'] = str_replace('-', '.', $rows[$key]['date']);
  47. }
  48. $this->success('成功',$list);
  49. }
  50. /**
  51. * 获取工序大废品惩奖侧边栏根据工单
  52. * @ApiMethod (GET)
  53. */
  54. public function getTabByGd()
  55. {
  56. //get请求
  57. if(!$this->request->isGet()){
  58. $this->error('请求方式错误');
  59. }
  60. $rows = db()->table('db_大废品')
  61. ->field('sczl_gdbh,rtrim(g.成品名称) as 成品名称')
  62. ->join('工单_基本资料 g','g.Gd_gdbh=db_大废品.sczl_gdbh','LEFT')
  63. ->group('sczl_gdbh')
  64. ->whereTime('db_大废品.sys_rq', '>=', strtotime('-60 days'))
  65. ->order('sczl_gdbh desc')
  66. ->select();
  67. foreach($rows as $key=>$value){
  68. $data[$key]['label']=$value['sczl_gdbh'].' 【'.$value['成品名称'].'】';
  69. $data[$key]['sczl_gdbh']=$value['sczl_gdbh'];
  70. }
  71. $this->success('成功',$data);
  72. }
  73. /**
  74. * 获取工序大废品惩奖列表
  75. * @ApiMethod (GET)
  76. * @param string $date 时间
  77. */
  78. public function getList()
  79. {
  80. //get请求
  81. if(!$this->request->isGet()){
  82. $this->error('请求方式错误');
  83. }
  84. $req = $this->request->param();
  85. $rq = $req['date'];
  86. $page = 1;
  87. $limit = 15;
  88. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  89. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  90. $date = substr($req['date'],0,10);
  91. $req['date'] = str_replace('.','-',$date);
  92. $where = [];
  93. if (isset($req['date']) && !empty($req['date'])){
  94. if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $rq)>0){
  95. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  96. }else{
  97. $where['sczl_rq'] = ['LIKE',$req['date'].'%'];
  98. }
  99. }else{
  100. $this->error('参数错误');
  101. }
  102. $res = db()->table('db_大废品')
  103. ->field('sczl_gdbh, LEFT(sczl_rq, 10) as sczl_rq, rtrim(sczl_numDesc) as sczl_numDesc, sczl_ls, sczl_yjno,
  104. rtrim(责任部门) as 责任部门,sczl_cl,
  105. rtrim(sczl_fplxA) as sczl_fplxA, sczl_fplxB, jl_jtbh as Jl_bzdh, JL_bh1,
  106. sczl_jtbh as sczl_bzdh, sczl_bh1, sczl_je1, sczl_bh2, sczl_je2, rtrim(sys_id) as sys_id, sys_rq, UniqId')
  107. ->where('sczl_gdbh',$req['date'])
  108. ->order('UniqId desc')
  109. ->page($page,$limit)
  110. ->select();
  111. if($res){
  112. $rows=$res;
  113. $total = db()->table('db_大废品')->where('sczl_gdbh',$req['date'])->count();;
  114. }else{
  115. $rows = db()->table('db_大废品')
  116. ->field('sczl_gdbh, LEFT(sczl_rq, 10) as sczl_rq, rtrim(sczl_numDesc) as sczl_numDesc, sczl_ls, sczl_yjno,
  117. rtrim(责任部门) as 责任部门, sczl_cl,
  118. rtrim(sczl_fplxA) as sczl_fplxA, sczl_fplxB, jl_jtbh as Jl_bzdh, JL_bh1,
  119. sczl_jtbh as sczl_bzdh, sczl_bh1, sczl_je1, sczl_bh2, sczl_je2, rtrim(sys_id) as sys_id, sys_rq, UniqId')
  120. ->where($where)
  121. ->order('UniqId desc')
  122. ->page($page,$limit)
  123. ->select();
  124. $total = db()->table('db_大废品')->where($where)->count();
  125. }
  126. $gd = db()->table('工单_印件资料')->column('Yj_Gdbh, yj_yjmc');
  127. $rs = db()->table('人事_基本资料')->where('员工姓名','<>','通用编号')->column('员工编号, 员工姓名');
  128. foreach ($rows as $key=>$value) {
  129. $rows[$key]['yj_yjmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? sprintf("%02d", $value['sczl_yjno']).'-'.trim($gd[$value['sczl_gdbh']]) : '';
  130. $rows[$key]['JL_bh1'] = array_key_exists($value['JL_bh1'],$rs) ? trim($rs[$value['JL_bh1']]) : '';
  131. $rows[$key]['sczl_bh1'] = array_key_exists($value['sczl_bh1'],$rs) ? trim($rs[$value['sczl_bh1']]) : '';
  132. $rows[$key]['sczl_bh2'] = array_key_exists($value['sczl_bh2'],$rs) ? trim($rs[$value['sczl_bh2']]) : '';
  133. $rows[$key]['sczl_fplxB'] = $value['sczl_fplxB'] == 1 ? '制程废' : '';
  134. if ($rows[$key]['sczl_bh1'] != '' && $value['sczl_je1'] > 0){
  135. $rows[$key]['sczl_bh1'] = $rows[$key]['sczl_bh1'].'(-'.$value['sczl_je1'].')';
  136. }
  137. if ($rows[$key]['sczl_bh2'] != '' && $value['sczl_je2'] > 0){
  138. $rows[$key]['sczl_bh2'] = $rows[$key]['sczl_bh2'].'(-'.$value['sczl_je2'].')';
  139. }
  140. unset($rows[$key]['sczl_yjno']);
  141. }
  142. $data = [
  143. 'total' => $total,
  144. 'rows' => $rows,
  145. ];
  146. $this->success('成功',$data);
  147. }
  148. /**
  149. * 获取工序大废品惩奖信息
  150. * @ApiMethod (GET)
  151. * @param string $UniqId UniqId
  152. */
  153. public function getInfo()
  154. {
  155. //get请求
  156. if(!$this->request->isGet()){
  157. $this->error('请求方式错误');
  158. }
  159. $req = $this->request->param();
  160. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  161. $UniqId = $req['UniqId'];
  162. }else{
  163. $this->error('参数错误');
  164. }
  165. $rows = db()->table('db_大废品')->alias('d')
  166. ->field('sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc,sczl_yjno,rtrim(yj.yj_yjmc) as yj_yjmc,
  167. rtrim(sczl_gxmc) as sczl_gxmc,sczl_gxh,rtrim(sczl_numDesc) as sczl_numDesc,LEFT(sczl_rq, 10)
  168. as sczl_rq,sczl_cl,sczl_ls,rtrim(sczl_fplxA) as sczl_fplxA,sczl_fplxB,rtrim(责任部门) as 责任部门,
  169. rtrim(jl_bzdh) as Jl_bzdh,jl_jtbh,JL_bh1,JL_bh2,JL_bh3,JL_bh4,JL_bh5,JL_bh6,JL_bh7,JL_bh8,JL_bh9,
  170. rtrim(jl1.员工姓名) as jlname1,rtrim(jl2.员工姓名) as jlname2,rtrim(jl3.员工姓名) as jlname3
  171. ,rtrim(jl4.员工姓名) as jlname4,rtrim(jl5.员工姓名) as jlname5,rtrim(jl6.员工姓名) as jlname6
  172. ,rtrim(jl7.员工姓名) as jlname7,rtrim(jl8.员工姓名) as jlname8,rtrim(jl9.员工姓名) as jlname9
  173. ,JL_Je1,JL_Je2,JL_Je3,JL_Je4,JL_Je5,JL_Je6,JL_Je7,JL_Je8,JL_Je9,rtrim(sczl_bzdh) as sczl_bzdh,
  174. sczl_jtbh,sczl_bh1,sczl_bh2,sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,
  175. rtrim(jl_bzdh) as Jl_bzdh,jl_jtbh,JL_bh1,JL_bh2,JL_bh3,JL_bh4,JL_bh5,JL_bh6,JL_bh7,JL_bh8,JL_bh9,
  176. rtrim(zr1.员工姓名) as zrname1,rtrim(zr2.员工姓名) as zrname2,rtrim(zr3.员工姓名) as zrname3
  177. ,rtrim(zr4.员工姓名) as zrname4,rtrim(zr5.员工姓名) as zrname5,rtrim(zr6.员工姓名) as zrname6
  178. ,rtrim(zr7.员工姓名) as zrname7,rtrim(zr8.员工姓名) as zrname8,rtrim(zr9.员工姓名) as zrname9
  179. ,sczl_je1,sczl_je2,sczl_je3,sczl_je4,sczl_je5,sczl_je6,sczl_je7,sczl_je8,sczl_je9')
  180. ->join('工单_基本资料 g','g.Gd_gdbh=db_大废品.sczl_gdbh')
  181. ->join('工单_印件资料 yj','yj.Yj_Gdbh=db_大废品.sczl_gdbh','LEFT')
  182. ->join('人事_基本资料 jl1','jl1.员工编号=db_大废品.JL_bh1','LEFT')
  183. ->join('人事_基本资料 jl2','jl2.员工编号=db_大废品.JL_bh2','LEFT')
  184. ->join('人事_基本资料 jl3','jl3.员工编号=db_大废品.JL_bh3','LEFT')
  185. ->join('人事_基本资料 jl4','jl4.员工编号=db_大废品.JL_bh4','LEFT')
  186. ->join('人事_基本资料 jl5','jl5.员工编号=db_大废品.JL_bh5','LEFT')
  187. ->join('人事_基本资料 jl6','jl6.员工编号=db_大废品.JL_bh6','LEFT')
  188. ->join('人事_基本资料 jl7','jl7.员工编号=db_大废品.JL_bh7','LEFT')
  189. ->join('人事_基本资料 jl8','jl8.员工编号=db_大废品.JL_bh8','LEFT')
  190. ->join('人事_基本资料 jl9','jl9.员工编号=db_大废品.JL_bh9','LEFT')
  191. ->join('人事_基本资料 zr1','zr1.员工编号=db_大废品.sczl_bh1','LEFT')
  192. ->join('人事_基本资料 zr2','zr2.员工编号=db_大废品.sczl_bh2','LEFT')
  193. ->join('人事_基本资料 zr3','zr3.员工编号=db_大废品.sczl_bh3','LEFT')
  194. ->join('人事_基本资料 zr4','zr4.员工编号=db_大废品.sczl_bh4','LEFT')
  195. ->join('人事_基本资料 zr5','zr5.员工编号=db_大废品.sczl_bh5','LEFT')
  196. ->join('人事_基本资料 zr6','zr6.员工编号=db_大废品.sczl_bh6','LEFT')
  197. ->join('人事_基本资料 zr7','zr7.员工编号=db_大废品.sczl_bh7','LEFT')
  198. ->join('人事_基本资料 zr8','zr8.员工编号=db_大废品.sczl_bh8','LEFT')
  199. ->join('人事_基本资料 zr9','zr9.员工编号=db_大废品.sczl_bh9','LEFT')
  200. ->where('d.UniqId',$UniqId)->limit(1)->select();
  201. $this->success('成功',$rows);
  202. }
  203. /**
  204. * 工单编号获取
  205. * @return void
  206. * @throws \think\exception\DbException
  207. * @throws db\exception\DataNotFoundException
  208. * @throws db\exception\ModelNotFoundException
  209. */
  210. public function JunkWorkOrderList()
  211. {
  212. if ($this->request->isGet() === false){
  213. $this->error('非法请求');
  214. }
  215. $params = $this->request->param();
  216. if (empty($params['search'])){
  217. $this->error('参数错误');
  218. }
  219. $list = \db('工单_基本资料')
  220. ->field('rtrim(Gd_gdbh) as 工单编号,rtrim(成品名称) as 产品名称')
  221. ->where('Gd_gdbh','like','%'.$params['search'].'%')
  222. ->select();
  223. if (empty($list)){
  224. $this->success('未找到工单信息');
  225. }
  226. $this->success('成功',$list);
  227. }
  228. /**
  229. * 印件编号获取
  230. * @return void
  231. * @throws \think\exception\DbException
  232. * @throws db\exception\DataNotFoundException
  233. * @throws db\exception\ModelNotFoundException
  234. */
  235. public function PrintCodeList()
  236. {
  237. if ($this->request->isGet() === false){
  238. $this->error('非法请求');
  239. }
  240. $param = $this->request->param();
  241. if (empty($param['workorder'])){
  242. $this->error('参数错误');
  243. }
  244. $list = \db('工单_印件资料')
  245. ->field('rtrim(yj_Yjno) as 印件号,rtrim(yj_yjmc) as 印件名称')
  246. ->where('Yj_Gdbh',$param['workorder'])
  247. ->select();
  248. if (empty($list)){
  249. $this->success('未找到该工单印件');
  250. }
  251. $this->success('成功',$list);
  252. }
  253. /**
  254. * 工单工序获取
  255. * @return void
  256. * @throws \think\exception\DbException
  257. * @throws db\exception\DataNotFoundException
  258. * @throws db\exception\ModelNotFoundException
  259. */
  260. public function ProcessList()
  261. {
  262. if ($this->request->isGet() === false){
  263. $this->error('非法请求');
  264. }
  265. $param = $this->request->param();
  266. if (empty($param['workorder']) || empty($param['yjno'])){
  267. $this->error('参数错误');
  268. }
  269. $list = \db('工单_工艺资料')
  270. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc')
  271. ->where('Gy0_gdbh',$param['workorder'])
  272. ->where('Gy0_yjno',$param['yjno'])
  273. ->select();
  274. if (empty($list)){
  275. $this->success('未找到该工单工艺');
  276. }
  277. $data = [];
  278. foreach ($list as $key=>$value){
  279. if ((int)$value['gxh'] < 10){
  280. $value['gxh'] = '0'.$value['gxh'];
  281. }
  282. $data[$key] = $value['gxh'].'-'.$value['gxmc'];
  283. }
  284. $this->success('成功',$data);
  285. }
  286. /**
  287. * 机台编号获取
  288. * @return void
  289. * @throws \think\exception\DbException
  290. * @throws db\exception\DataNotFoundException
  291. * @throws db\exception\ModelNotFoundException
  292. */
  293. public function MachineList()
  294. {
  295. if ($this->request->isGet() === false){
  296. $this->error('非法请求');
  297. }
  298. $param = $this->request->param();
  299. $list = \db('设备_产量计酬')
  300. ->alias('a')
  301. ->join('人事_基本资料 b1','a.sczl_bh1 = b1.员工编号','left')
  302. ->join('人事_基本资料 b2','a.sczl_bh2 = b2.员工编号','left')
  303. ->join('人事_基本资料 b3','a.sczl_bh3 = b3.员工编号','left')
  304. ->join('人事_基本资料 b4','a.sczl_bh4 = b4.员工编号','left')
  305. ->join('人事_基本资料 b5','a.sczl_bh5 = b5.员工编号','left')
  306. ->join('人事_基本资料 b6','a.sczl_bh6 = b6.员工编号','left')
  307. ->join('人事_基本资料 b7','a.sczl_bh7 = b7.员工编号','left')
  308. ->join('人事_基本资料 b8','a.sczl_bh8 = b8.员工编号','left')
  309. ->join('人事_基本资料 b9','a.sczl_bh9 = b9.员工编号','left')
  310. ->join('人事_基本资料 b10','a.sczl_bh10 = b10.员工编号','left')
  311. ->field('a.sczl_gxmc as 工序名称,a.sczl_jtbh as 机台编号,a.sczl_bh1 as 员工编号1,rtrim(b1.员工姓名) as 员工姓名1
  312. ,a.sczl_bh2 as 员工编号2,rtrim(b2.员工姓名) as 员工姓名2,a.sczl_bh3 as 员工编号3,rtrim(b3.员工姓名) as 员工姓名3
  313. ,a.sczl_bh4 as 员工编号4,rtrim(b4.员工姓名) as 员工姓名4,a.sczl_bh5 as 员工编号5,rtrim(b5.员工姓名) as 员工姓名5
  314. ,a.sczl_bh6 as 员工编号6,rtrim(b6.员工姓名) as 员工姓名6,a.sczl_bh7 as 员工编号7,rtrim(b7.员工姓名) as 员工姓名7
  315. ,a.sczl_bh8 as 员工编号8,rtrim(b8.员工姓名) as 员工姓名8,a.sczl_bh9 as 员工编号9,rtrim(b9.员工姓名) as 员工姓名9
  316. ,a.sczl_bh10 as 员工编号10,rtrim(b10.员工姓名) as 员工姓名10')
  317. ->where('a.sczl_gdbh',$param['gdbh'])
  318. ->where('a.sczl_yjno',$param['yjno'])
  319. ->where('a.sczl_bzdh','like',substr($param['bzdh'],0,1).'%')
  320. ->group('机台编号,员工编号1,员工编号2,员工编号3,员工编号4,员工编号5,员工编号6,员工编号7,员工编号8,员工编号9,员工编号10')
  321. ->select();
  322. // $list = \db('设备_基本资料')
  323. // ->field('rtrim(设备编号) as 设备编号')
  324. // ->where('sys_sbID','<>','')
  325. // ->select();
  326. if (empty($list)){
  327. $this->success('未找到机台编号');
  328. }
  329. $this->success('成功',$list);
  330. }
  331. /**
  332. * 机台班组获取
  333. * @return void
  334. * @throws \think\exception\DbException
  335. * @throws db\exception\DataNotFoundException
  336. * @throws db\exception\ModelNotFoundException
  337. */
  338. public function MachineClassList()
  339. {
  340. if ($this->request->isGet() === false){
  341. $this->error('非法请求');
  342. }
  343. $param = $this->request->param();
  344. if (empty($param['machine'])){
  345. $this->error('参数错误');
  346. }
  347. $list = \db('设备_班组资料')
  348. ->where('sczl_jtbh',$param['machine'])
  349. ->field('rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,
  350. rtrim(sczl_bh4) as bh4,rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,
  351. rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
  352. rtrim(sczl_bh10) as bh10,rtrim(sczl_bzdh) as 班组代号')
  353. ->select();
  354. if (empty($list)){
  355. $this->success('未找到该机台班组');
  356. }
  357. foreach ($list as $key=>$value){
  358. for ($i=1;$i<=10;$i++){
  359. if (!empty($value['bh'.$i])){
  360. $name = \db('人事_基本资料')->where('员工编号',$value['bh'.$i])->field('rtrim(员工姓名) as name')->find();
  361. if (isset($name['name'])){
  362. $list[$key]['组员'.$i] = [
  363. '编号' => $value['bh'.$i],
  364. '姓名' => $name['name']
  365. ];
  366. }
  367. }else{
  368. $list[$key]['组员'.$i] = [
  369. '编号' => '',
  370. '姓名' => ''
  371. ];
  372. }
  373. unset($list[$key]['bh'.$i]);
  374. }
  375. }
  376. $this->success('成功',$list);
  377. }
  378. /**
  379. * 大废品数据修改
  380. * @return void
  381. * @throws \think\Exception
  382. * @throws \think\exception\PDOException
  383. * @throws db\exception\BindParamException
  384. */
  385. public function JunkDetailEdit()
  386. {
  387. // 判断请求方式是否为 POST
  388. if (Request::instance()->isPost() === false) {
  389. $this->error('非法请求');
  390. }
  391. // 获取请求参数
  392. $param = Request::instance()->post();
  393. if (empty($param['sczl_gdbh']) || empty($param['UniqId'])) {
  394. $this->error('参数错误');
  395. }
  396. $param['mod_rq'] = date('Y-m-d H:i:s', time());
  397. $data = $param['sczl_rq'].' 00:00:00';
  398. // 奖励班组封顶限制【记录是否存在超限的标志】
  399. $over_limit = false;
  400. // 遍历 JL_bh1 ~ JL_bh10,检查当天和本月金额限制
  401. for ($i = 1; $i <= 10; $i++) {
  402. $jl_bh = 'JL_bh' . $i; // 获取 JL_bh1 到 JL_bh10
  403. $jl_je = 'JL_Je' . $i; // 获取 JL_Je1 到 JL_Je10
  404. if (!empty($param[$jl_bh]) && isset($param[$jl_je])) { // 确保 JL_bh 和 JL_Je 不为空
  405. $person_id = $param[$jl_bh]; // 当前人员的 ID
  406. $amount = $param[$jl_je]; // 当前人员的金额
  407. // 获取当天的所有记录金额总和
  408. $daily_total = \db('db_大废品')
  409. ->where('sczl_rq', $data)
  410. ->sum($jl_je);
  411. $daUniqId = \db('db_大废品')
  412. ->where('UniqId', $param['UniqId'])
  413. ->sum($jl_je);
  414. // 将当天的金额总和与接口传过来的金额加起来
  415. $total_amount = ($daily_total + $amount) - $daUniqId; // 假设传入的是 JL_Je1
  416. // 检查金额是否超过 200 元
  417. if ($total_amount > 200) {
  418. $this->error("【{$person_id}】当天金额超限!当天金额不能超过 200 元!");
  419. $over_limit = true;
  420. break;
  421. }
  422. // 获取当月的所有记录金额总和
  423. $month = substr($data, 5, 2);
  424. $year = substr($data, 0, 4);
  425. $start_date = $year . '-' . $month . '-01';
  426. $end_date = date('Y-m-t', strtotime($start_date));
  427. $monthly_total = \db('db_大废品')
  428. ->whereBetween('sczl_rq', [$start_date, $end_date])
  429. ->where($jl_bh, $person_id)
  430. ->sum($jl_je);
  431. // 检查本月是否超过 1500 元
  432. if ($monthly_total + $amount - $daUniqId > 1500) {
  433. $this->error("【{$person_id}】本月金额超限!本月金额不能超过 1500 元!");
  434. $over_limit = true;
  435. break;
  436. }
  437. }
  438. }
  439. // 如果存在超限,停止执行
  440. if ($over_limit) {
  441. return;
  442. }
  443. // 扣罚金额封顶限制
  444. $kfover_limit = false;
  445. // 检查 sczl_bh1 的限制(不能超过 1000 元)
  446. if (!empty($param['sczl_bh1']) && isset($param['sczl_je1'])) {
  447. $person_id = $param['sczl_bh1'];
  448. $amount = $param['sczl_je1'];
  449. // 获取该人员当天的扣罚金额总和
  450. $daily_total = \db('db_大废品')
  451. ->where('sczl_rq', $data)
  452. ->where('sczl_bh1', $person_id)
  453. ->sum('sczl_je1');
  454. $daUniqId = \db('db_大废品')
  455. ->where('UniqId', $param['UniqId'])
  456. ->sum("sczl_je1");
  457. // 判断是否超过 1000 元
  458. if (($daily_total + $amount) - $daUniqId > 1000) {
  459. $this->error("【{$person_id}】当天扣罚金额超限!当天扣罚金额不能超过 1000 元!");
  460. $kfover_limit = true;
  461. }
  462. }
  463. // 遍历 sczl_bh2 ~ sczl_bh10,检查当天金额是否超过 500 元
  464. for ($i = 2; $i <= 10; $i++) {
  465. $sczl_bh = 'sczl_bh' . $i;
  466. $sczl_je = 'sczl_je' . $i;
  467. if (!empty($param[$sczl_bh]) && isset($param[$sczl_je])) {
  468. $person_id = $param[$sczl_bh];
  469. $amount = $param[$sczl_je];
  470. // 获取该人员当天的扣罚金额总和
  471. $daily_total = \db('db_大废品')
  472. ->where('sczl_rq', $data)
  473. // ->where($sczl_bh, $person_id)
  474. ->sum($sczl_je);
  475. $daUniqId = \db('db_大废品')
  476. ->where('UniqId', $param['UniqId'])
  477. ->sum($sczl_je);
  478. $total_amount = ($daily_total + $amount) - $daUniqId; // 假设传入的是 JL_Je1
  479. // 判断是否超过 500 元
  480. if ($total_amount > 500) {
  481. $this->error("【{$person_id}】当天扣罚金额超限!当天扣罚金额不能超过 500 元!");
  482. $kfover_limit = true;
  483. break; // 如果超限,停止检查
  484. }
  485. }
  486. }
  487. // 如果超限就不插入数据
  488. if ($kfover_limit) {
  489. return; // 直接终止
  490. }
  491. // 执行更新操作
  492. // unset($data['UniqId']);
  493. $sql = \db('db_大废品')
  494. ->where('UniqId', $param['UniqId'])
  495. ->fetchSql(true)
  496. ->update($param);
  497. $res = \db()->query($sql);
  498. if ($res !== false) {
  499. $this->success('修改成功');
  500. } else {
  501. $this->error('修改失败');
  502. }
  503. }
  504. /**
  505. * 大废品数据添加
  506. * @return void
  507. * @throws \think\exception\PDOException
  508. * @throws db\exception\BindParamException
  509. */
  510. public function JunkDetailAdd()
  511. {
  512. if (Request::instance()->isPost() === false) {
  513. $this->error('非法请求');
  514. }
  515. $param = Request::instance()->post();
  516. if (empty($param['sczl_gdbh'])) {
  517. $this->error('参数错误');
  518. }
  519. // 获取最后一条记录的UniqId
  520. $lastID = \db('db_大废品')->order('UniqId desc')->value('UniqId');
  521. // 设置当前时间和其他初始化数据
  522. $param['sys_rq'] = date('Y-m-d H:i:s', time());
  523. $param['mod_rq'] = '1900-01-01 00:00:00';
  524. $param['UniqId'] = $lastID + 1;
  525. $data = $param['sczl_rq'];
  526. //奖励班组封顶限制【记录是否存在超限的标志】
  527. $over_limit = false;
  528. // 遍历参数,检查每个人当天和本月的消费情况
  529. for ($i = 1; $i <= 10; $i++) {
  530. $jl_bh = 'JL_bh' . $i;
  531. $jl_je = 'JL_Je' . $i;
  532. if (!empty($param[$jl_bh]) && isset($param[$jl_je])) {
  533. $person_id = $param[$jl_bh];
  534. $amount = $param[$jl_je];
  535. // 获取当天的所有记录金额总和
  536. $daily_total = \db('db_大废品')
  537. ->where('sczl_rq', $data)
  538. ->where($jl_bh, $person_id)
  539. ->sum($jl_je);
  540. // 获取当月的所有记录金额总和
  541. $month = substr($data, 5, 2);
  542. $year = substr($data, 0, 4);
  543. $start_date = $year . '-' . $month . '-01';
  544. $end_date = date('Y-m-t', strtotime($start_date));
  545. $monthly_total = \db('db_大废品')
  546. ->whereBetween('sczl_rq', [$start_date, $end_date])
  547. ->where($jl_bh, $person_id)
  548. ->sum($jl_je);
  549. // 检查当天是否超过 200
  550. if ($daily_total + ($amount * $param['sczl_cl']) > 200) {
  551. $this->error("【{$person_id}】当天金额超限!当天金额不能超过200元!");
  552. $over_limit = true;
  553. break;
  554. }
  555. // 检查本月是否超过 1500
  556. if ($monthly_total + ($amount * $param['sczl_cl']) > 1500) {
  557. $this->error("【{$person_id}】本月金额超限!本月金额不能超过1500元!");
  558. $over_limit = true;
  559. break;
  560. }
  561. }
  562. }
  563. // 如果超限就不插入数据
  564. if ($over_limit) {
  565. // 提示超限后停止执行
  566. return;
  567. }
  568. // 记录是否存在超限
  569. $kfover_limit = false;
  570. // 获取 sczl_bh1 的值,并检查它是否存在
  571. if (!empty($param['sczl_bh1']) && isset($param['sczl_je1'])) {
  572. $person_id = $param['sczl_bh1'];
  573. $amount = $param['sczl_je1'];
  574. // 获取该人员当天的扣罚金额总和
  575. $daily_total = \db('db_大废品')
  576. ->where('sczl_rq', $data)
  577. ->where('sczl_bh1', $person_id)
  578. ->sum('sczl_je1');
  579. // 判断是否超过 1000
  580. if ($daily_total + ($amount * $param['sczl_cl']) > 1000) {
  581. $this->error("【{$person_id}】当天扣罚金额超限!当天扣罚金额不能超过 1000 元!");
  582. $kfover_limit = true;
  583. }
  584. }
  585. // 遍历 sczl_bh2 ~ sczl_bh10
  586. for ($i = 2; $i <= 10; $i++) {
  587. $sczl_bh = 'sczl_bh' . $i;
  588. $sczl_je = 'sczl_je' . $i;
  589. if (!empty($param[$sczl_bh]) && isset($param[$sczl_je])) {
  590. $person_id = $param[$sczl_bh];
  591. $amount = $param[$sczl_je];
  592. // 获取该人员当天的扣罚金额总和
  593. $daily_total = \db('db_大废品')
  594. ->where('sczl_rq', $data)
  595. ->where($sczl_bh, $person_id)
  596. ->sum($sczl_je);
  597. // 判断是否超过 500
  598. if ($daily_total + ($amount * $param['sczl_cl']) > 500) {
  599. $this->error("【{$person_id}】当天扣罚金额超限!当天扣罚金额不能超过 500 元!");
  600. $kfover_limit = true;
  601. break; // 只要有一个超限就停止检查
  602. }
  603. }
  604. }
  605. // 如果超限就不插入数据
  606. if ($kfover_limit) {
  607. return; // 直接终止
  608. }
  609. // 插入数据
  610. $sql = \db('db_大废品')->fetchSql(true)->insert($param);
  611. $res = \db()->query($sql);
  612. if ($res !== false) {
  613. $this->success('添加成功');
  614. } else {
  615. $this->error('失败');
  616. }
  617. }
  618. /**
  619. * 大废品数据删除
  620. * @return void
  621. * @throws \think\Exception
  622. * @throws \think\exception\PDOException
  623. */
  624. public function JunkDetailDel()
  625. {
  626. if ($this->request->isGet() === false){
  627. $this->error('非法请求');
  628. }
  629. $param = $this->request->param();
  630. if (empty($param['UniqId'])){
  631. $this->error('参数错误');
  632. }
  633. $idList = explode(',',$param['UniqId']);
  634. $res = \db('db_大废品')
  635. ->whereIn('UniqId',$idList)
  636. ->delete();
  637. if ($res !== false){
  638. $this->success('删除成功');
  639. }else{
  640. $this->error('失败');
  641. }
  642. }
  643. }