| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | 
							- <?php
 
- namespace app\common\service;
 
- use think\Db;
 
- class UserService
 
- {
 
-     private $model =  null;
 
-     /**
 
-      * 初始化方法
 
-      */
 
-     public function __construct()
 
-     {
 
-         $this->model = Db::name('user');
 
-     }
 
-     /**
 
-      * 用户换绑
 
-      * @return void
 
-      */
 
-     public function userBindCompany($params=[])
 
-     {
 
-         $result = [
 
-             'status' => 1,
 
-             'msg' => '操作成功',
 
-             'data' => [],
 
-         ];
 
-         try {
 
-             $userId = isset($params['user_id']) ? $params['user_id'] : 0;
 
-             $companyId = isset($params['company_id']) ? $params['company_id'] : 0;
 
-             $where['id'] = $userId;
 
-             $user = Db::name('user')->where($where['id'])->find();
 
-             if (!empty($user)) {
 
-                 if ($user['company_id'] != $companyId) {
 
-                     $userData['company_id'] = $companyId;
 
-                     $userData['updatetime'] = time();
 
-                     $userRes = Db::name('user')->where($where['id'])->update($userData);
 
-                     if (!$userRes) {
 
-                         throw new Exception('操作失败');
 
-                     }
 
-                 }
 
-             }
 
-         } catch (Exception $e) {
 
-             $result['status'] = 0;
 
-             $result['msg'] = $e->getMessage();
 
-         }
 
-         return $result;
 
-     }
 
-     /**
 
-      * 用户绑定门店和钱包
 
-      * @return void
 
-      */
 
-     public function userWallet($params=[])
 
-     {
 
-         $result = [
 
-             'status' => 1,
 
-             'msg' => '操作成功',
 
-             'data' => [],
 
-         ];
 
-         try {
 
-             $userId = isset($params['user_id']) ? $params['user_id'] : 0;
 
-             $companyId = isset($params['company_id']) ? $params['company_id'] : 0;
 
-             $comefrom = isset($params['comefrom']) ? $params['comefrom'] : '';
 
-             $bindRes = $this->userBindCompany($params);//绑定门店
 
-             if (!$bindRes['status']) {
 
-                 throw new Exception($bindRes['msg']);
 
-             }
 
-             $where['user_id'] = $userId;
 
-             $where['company_id'] = $companyId;
 
-             $userWallet = Db::name('user_wallet')->where($where['id'])->find();
 
-             $time = time();
 
-             if (empty($userWallet)) {
 
-                 $userWalletData = [
 
-                     'user_id' => $userId,
 
-                     'company_id' => $companyId,
 
-                     'money' => 0.00,
 
-                     'createtime' => $time,
 
-                     'comefrom' => $comefrom,
 
-                 ];
 
-                 $userWalletRes = Db::name('user_wallet')->insertGetId($userWalletData);
 
-                 if (!$userWalletRes) {
 
-                     throw new Exception('生成钱包失败');
 
-                 }
 
-             }
 
-         } catch (Exception $e) {
 
-             $result['status'] = 0;
 
-             $result['msg'] = $e->getMessage();
 
-         }
 
-         return $result;
 
-     }
 
- }
 
 
  |