12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\admin\controller;
- use app\common\model\WorkerBalance;
- use think\App;
- use think\Db;
- use think\Exception;
- class Balance extends Auth {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->model = new \app\common\model\Worker();
- }
- public function index() {
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $title = input('title', '', 'trim');
- $map = [];
- if ($title) {
- $map['name'] = $title;
- }
- $recommend = input('recommend', '', 'trim');
- if ($recommend != '') {
- $map['recommend'] = $recommend;
- }
- $enable = input('enable', '', 'trim');
- if ($enable != '') {
- $map['enable'] = $enable;
- }
- $gender = input('gender', '', 'trim');
- if ($gender != '') {
- $map['gender'] = $gender;
- }
- $map['balance'] = 1;
- //数据查询
- $result = $this->model->lists($this->orgId, $map, $page, $length);
- return json($result);
- }
- else {
- return $this->fetch();
- }
- }
- public function js(){
- $data = request()->post();
- $ids = $data['ids'];
- $balanceModel = new WorkerBalance();
- $model = new \app\common\model\Worker();
- $succ = 0;
- $err = 0;
- $er = [];
- $logId = Db::name('settlement_log')
- ->insertGetId([
- 'user_id'=>$this->userId,
- 'org_id'=>$this->orgId,
- 'create_time'=>date('Y-m-d H:i:s'),
- ]);
- if(!$logId){
- $this->error('结算记录保存失败');
- }
- foreach ($ids as $k=>$id){
- $user_id = Db::name('worker')
- ->where('id',$id)
- ->value('user_id');
- $info = $model->getUserInfo($user_id);
- $res = $balanceModel->saveWorkerBalance($this->orgId,
- -$info['balance'],$this->userId,$id,2,'',0,$logId);
- if($res){
- $succ++;
- }else{
- $err++;
- $er[] = $info['real_name'].':'.$balanceModel->getError();
- }
- }
- if(empty($er)){
- $msg = '成功:'.$succ.'失败:'.$err;
- $a = ['code'=>0,'msg'=>$msg];
- }else{
- $msg = '成功:'.$succ.'失败:'.$err.' 失败原因:'.json_encode($er,JSON_UNESCAPED_UNICODE);
- $a = ['code'=>1,'msg'=>$msg];
- }
- $this->success('','',$a);
- }
- }
|