diff --git a/.gitignore b/.gitignore index 3fc276b..ff712e7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ yarn-error.log .idea .vscode/launch.json +/storage/debugbar \ No newline at end of file diff --git a/app/Admin/Common/Auth.php b/app/Admin/Common/Auth.php new file mode 100644 index 0000000..30b0498 --- /dev/null +++ b/app/Admin/Common/Auth.php @@ -0,0 +1,57 @@ +>1.添加市场经理前,去查询是否已存在相同的帐号 + $count = $adu->where(['username' => $form->phone])->count(); + if ($count) { + $row->delete(); + return '-1'; + } + //>>2.添加市场经理登陆帐号 + $adu->username = $form->phone; + $adu->password = Hash::make(substr($form->phone, -5)); + $adu->name = $form->name; + $adu->status = $form->status; + $res = $adu->save(); + if (!$res) { + //删除刚添加数据 + $row->delete(); + return '-2'; + } + //>>3.将帐号id关联 + $row->admin_user_id = $adu->id; + $row->save(); + + //添加到admin roles中 + $lanzu_role = AdminRoles::where('slug', $roles)->first(); + $aru = new AdminRoleUsers(); + $aru->role_id = $lanzu_role->id; + $aru->user_id = $adu->id; + $aru->save(); + + } +} diff --git a/app/Admin/Common/Images.php b/app/Admin/Common/Images.php new file mode 100644 index 0000000..e4e384a --- /dev/null +++ b/app/Admin/Common/Images.php @@ -0,0 +1,144 @@ +select('appid','appsecret') + ->where('uniacid', 2) + ->first(); + $appid=$row->appid; + $secret=$row->appsecret; + $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0); + $data = curl_exec($ch); + curl_close($ch); + $data = json_decode($data,true); + return $data['access_token']; + } + + public function createQrCode($param,$path) + { + $access_token = $this->getWxToken(); + $data=array( + 'scene'=>$param, + "page"=>$path, + "width"=>100 + ); + $data = json_encode($data); + $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token.""; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0); + curl_setopt($ch, CURLOPT_POST,1); + curl_setopt($ch, CURLOPT_POSTFIELDS,$data); + $data = curl_exec($ch); + curl_close($ch); + return $data; + + } + + /** + * 上传文件到oss + * @param $base64 //文件流 + * @param $fileName //文件名称 + * @return bool + */ + public function uploadOss($base64,$fileName) + { + return Storage::put($fileName,$base64); + } + + + public function test() + { + $wx_head = 'http://www.marketmanage.com/uploads/20200728/d5a491cd3d8d071e3212c3478e8e35a1.jpg'; + $avatar_file = file_get_contents($wx_head); + file_put_contents('./logo.jpg',$avatar_file); + $logo = $this->changeAvatar($avatar_file); + file_put_contents('./logo_new.jpg',$logo); + + + //$qr_code = $this->createQrCode('',''); + + + } + + + public function changeAvatar($avatar) + { + //处理用户头像为圆形icon + $avatar = imagecreatefromstring($avatar); + $w = imagesx($avatar)-5; + $h = imagesy($avatar)-5; + $w = min($w, $h); + $h = $w; + + $img = imagecreatetruecolor($w, $h); + imagesavealpha($img, true); + $bg = imagecolorallocatealpha($img, 255, 255, 255, 127); + imagefill($img, 0, 0, $bg); + + $r = $w / 2; //圆半径 + $y_x = $r; //圆心X坐标 + $y_y = $r; //圆心Y坐标 + for ($x = 0; $x < $w; $x++) { + for ($y = 0; $y < $h; $y++) { + $rgbColor = imagecolorat($avatar, $x, $y); + + if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) { + imagesetpixel($img, $x, $y, $rgbColor); + } + } + } + + ob_start(); + imagepng($img); + imagedestroy($img); + imagedestroy($avatar); + $contents = ob_get_contents(); //读取缓存区的内容 + ob_end_clean(); //清空缓存区 + return $contents; + } + + + public function makeOnePic($qr_code, $logo) //二维码与头像组合 + { + $qr_code = imagecreatefromstring($qr_code); //生成的二维码底色为白色 + //设置二维码为透明底 + imagesavealpha($qr_code, true); //这个设置一定要加上 + $bg = imagecolorallocatealpha($qr_code, 255, 255, 255, 127); //拾取一个完全透明的颜色,最后一个参数127为全透明 + imagefill($qr_code, 0, 0, $bg); + $icon = imagecreatefromstring($logo); //生成中间圆形logo (微信头像获取到的logo的大小为132px 132px) + + $qr_width = imagesx($qr_code); //二维码图片宽度 + $lg_width = imagesx($icon); //logo图片宽度 + $lg_height = imagesy($icon); //logo图片高度 + + $qr_lg_width = $qr_width / 2.2; + $scale = $lg_width / $qr_lg_width; + $qr_lg_height = $lg_height / $scale; + $start_width = ($qr_width - $lg_width) / 2 ; //(获取logo的左上方的位置:( 外部的正方形-logo的宽 ) / 2,我这边存在1px的偏差 我就给+2啦) + + imagecopyresampled($qr_code, $icon, $start_width, $start_width, 0, 0, $qr_lg_width, $qr_lg_height, $lg_width, $lg_height); + imagejpeg($qr_code,'./qrcode.png'); //保存 + + imagedestroy($qr_code); + imagedestroy($icon); + } +} diff --git a/app/Admin/Controllers/LanzuCsInfoController.php b/app/Admin/Controllers/LanzuCsInfoController.php new file mode 100644 index 0000000..9cfe998 --- /dev/null +++ b/app/Admin/Controllers/LanzuCsInfoController.php @@ -0,0 +1,118 @@ +isRole('lanzu_cs')){//如何是社区站点角色登陆,则只能看到自己的信息 + $grid->model()->where('admin_user_id', $user->id); + } + $grid->id->sortable(); + $grid->name; + $grid->phone; + + $grid->column('qrcode_path','二维码')->image('',50,50); + $grid->status('状态')->using(['禁用', '启用']); + $grid->address; + $grid->created_at->display(function ($time){ + return date('Y-m-d H:i',$time); + }); + $grid->disableViewButton(); + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id'); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new LanzuCsInfo(), function (Show $show) { + $show->id; + $show->name; + $show->phone; + $show->address; + $show->admin_user_id; + $show->status; + $show->created_at; + $show->updated_at; + }); + } + + /** + * Make a form builder. + * @return Form + */ + protected function form() + { + return Form::make(new LanzuCsInfo(), function (Form $form) { + $form->display('id'); + $form->text('name','名称')->required(); + $form->text('user_id','用户ID')->required(); + $form->tel('phone')->required(); + $form->text('address','社区地址')->required(); + $form->radio('status', '状态')->options(['禁用', '启用'])->default(1); + $form->saved(function (Form $form,$cid){ + $model = new modelCsInfo(); + if ($form->isCreating()) { + //>>1.添加登录帐号 + $res = Auth::addAdminUser($form,$model,$cid,'lanzu_cs'); + if ($res==-1){ + return $form->error('该手机号作为登陆帐号已存在!'); + }elseif ($res==-2){ + return $form->error('添加失败!'); + } + + //>>2.生成小程序二维码 + $images = new Images(); + $param= 'p=index&sid=2'; + $path= 'zh_cjdianc/pages/Liar/loginindex'; + $qrcode = $images->createQrCode($param,$path); + $fileName = 'public/upload/' .'qrcode'.'/'. date('Y') . '/' . date('m-d') . '/' . rand(100000000000000,999999999999999).'.png'; + $result = $images->uploadOss($qrcode,$fileName); + if ($result==true){ + //>>3.保存二维码路径 + $cs = $model->find($cid); + $cs->qrcode_path = $fileName; + $cs->save(); + } + } else { + //>>4.编辑时同步登陆帐号状态 + $adu = new AdminUsers(); + $id = $form->getKey(); + $row = $model::find($id); + $ad = $adu->find($row->admin_user_id); + $ad->status = $form->status; + $ad->save(); + } + }); + }); + } +} diff --git a/app/Admin/Controllers/LanzuCsWithdrawController.php b/app/Admin/Controllers/LanzuCsWithdrawController.php new file mode 100644 index 0000000..2d0e107 --- /dev/null +++ b/app/Admin/Controllers/LanzuCsWithdrawController.php @@ -0,0 +1,74 @@ +id->sortable(); + $grid->cs_id; + $grid->money; + $grid->status; + $grid->is_pay; + $grid->created_at; + $grid->updated_at->sortable(); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id'); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new LanzuCsWithdraw(), function (Show $show) { + $show->id; + $show->cs_id; + $show->money; + $show->status; + $show->is_pay; + $show->created_at; + $show->updated_at; + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new LanzuCsWithdraw(), function (Form $form) { + $form->display('id'); + $form->text('cs_id'); + $form->text('money'); + $form->text('status'); + $form->text('is_pay'); + + $form->display('created_at'); + $form->display('updated_at'); + }); + } +} diff --git a/app/Admin/Repositories/LanzuCsInfo.php b/app/Admin/Repositories/LanzuCsInfo.php new file mode 100644 index 0000000..a27b31a --- /dev/null +++ b/app/Admin/Repositories/LanzuCsInfo.php @@ -0,0 +1,16 @@ +resource('/store', 'ImsCjdcStoreController'); $router->resource('/mp_withdraw', 'LanzuMpWithdrawController'); $router->resource('/mm_withdraw', 'LanzuMmWithdrawController'); + $router->resource('/cs', 'LanzuCsInfoController'); + $router->resource('/cs_withdraw', 'LanzuCsWithdrawController'); $router->any('/mm_list', 'LanzuMmWithdrawController@mmInfoList'); $router->any('/api/getMarket', 'LanzuMmInfoController@getMarket'); diff --git a/app/Models/LanzuCsInfo.php b/app/Models/LanzuCsInfo.php new file mode 100644 index 0000000..30a29d4 --- /dev/null +++ b/app/Models/LanzuCsInfo.php @@ -0,0 +1,15 @@ + [ + 'LanzuCsInfo' => 'LanzuCsInfo', + ], + 'fields' => [ + 'name' => '名称', + 'phone' => '电话', + 'address' => '地址', + 'admin_user_id' => '系统登陆帐号', + 'status' => '状态 0/1/2 未审核/已审核', + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh-CN/lanzu-cs-withdraw.php b/resources/lang/zh-CN/lanzu-cs-withdraw.php new file mode 100644 index 0000000..3d44afe --- /dev/null +++ b/resources/lang/zh-CN/lanzu-cs-withdraw.php @@ -0,0 +1,14 @@ + [ + 'LanzuCsWithdraw' => 'LanzuCsWithdraw', + ], + 'fields' => [ + 'cs_id' => '关联的社区服务站id', + 'money' => '提现金额', + 'status' => '提现状态 0/1/-1 待审核/已同意/已拒绝', + 'is_pay' => '是否支付到账 0/1 否/是', + ], + 'options' => [ + ], +];