PayWages.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class PayWages extends Model
  8. {
  9. public function edit($userId){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'content' => input('content','','trim'),
  13. 'update_time' => date('Y-m-d H:i:s')
  14. ];
  15. $result = validate('PayWages')->check($data,[],'');
  16. if(true !== $result){
  17. HelpHander::error(validate('PayWages')->getError());
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  21. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  22. if(!$ret){
  23. HelpHander::error('操作失败');
  24. }
  25. Db::name('pay_wages_log')->insert([
  26. 'pwid' => $id,
  27. 'user_id' => $userId,
  28. 'content' => $data['content'],
  29. 'create_time' => date('Y-m-d H:i:s')
  30. ]);
  31. return true;
  32. }
  33. public function info($companyId){
  34. $lists = Db::name('pay_wages')
  35. ->where('company_id',$companyId)
  36. ->select();
  37. $lists = $lists?$lists:[];
  38. foreach ($lists as $k=>$v){
  39. $lists[$k]['content'] = json_decode($v['content'],true);
  40. }
  41. return $lists;
  42. }
  43. public function all(){
  44. $lists = $this
  45. ->field('id,content,type,company_id')
  46. ->order('id desc')
  47. ->select();
  48. $lists = $lists?$lists->toArray():[];
  49. foreach ($lists as $k=>$v){
  50. $lists[$k]['content'] = json_decode($v['content'],true);
  51. }
  52. return $lists;
  53. }
  54. }