Esempio n. 1
0
 /**
  * 绑定钉钉
  * @return [type] [description]
  */
 public function bindding($id, $type = 'bind')
 {
     if ($type == 'unbind') {
         $data = ['ding_uid' => '', 'ding_openid' => '', 'update_time' => NOW_TIME];
         if (Db::name('Member')->where('id', $id)->update($data)) {
             logs('用户钉钉成功解除绑定');
             return $this->success();
         } else {
             return $this->error();
         }
     } else {
         if (IS_POST) {
             $dingid = $this->request->post('dingid');
             if (empty($dingid)) {
                 return $this->error('必须选择一个钉钉用户');
             }
             $dingUser = Db::name('DingUser')->where('id', $dingid)->field('userid,openid')->find();
             if (!$dingUser) {
                 return $this->error('钉钉用户不存在');
             }
             $data = ['ding_openid' => $dingUser['openid'], 'ding_uid' => $dingUser['userid']];
             if (Db::name('member')->where(['id' => $id])->update($data)) {
                 logs('用户钉钉绑定成功', $data);
                 /* 发送钉钉消息通知 */
                 if ($this->request->post('notice')) {
                     parent::_initDing();
                     \tools\Ding\CompanyMessage::oa($dingUser['userid'], '', 30443659, '账户绑定成功', '您的账户与平台账户绑定成功', 'http://d.nxr.cjango.com/center/index?dd_nav_bgcolor=FF18B4ED');
                 }
                 return $this->success();
             } else {
                 return $this->error();
             }
         } else {
             $info = Db::name('Member')->where('id', $id)->find();
             if (!empty($info['ding_openid'])) {
                 $this->assign('info', $info);
                 $this->assign('ding', Db::name('DingUser')->where('openid', $info['ding_openid'])->find());
             } else {
                 $hasBindIds = Db::name('Member')->where('ding_openid', 'neq', '')->column('ding_openid') ?: [''];
                 $list = Db::name('DingUser')->where('openid', 'notin', $hasBindIds)->field('id,name')->select();
                 $this->assign('list', $list);
             }
         }
         return $this->fetch();
     }
 }