コード例 #1
0
 public function sendSMS(Request $request)
 {
     $m3_result = new M3Result();
     $phone = $request->input('phone', '');
     if ($phone == '') {
         $m3_result->status = 1;
         $m3_result->message = '手机号不能为空';
         return $m3_result->toJson();
     }
     if (strlen($phone) != 11 || $phone[0] != '1') {
         $m3_result->status = 2;
         $m3_result->message = '手机格式不正确';
         return $m3_result->toJson();
     }
     $sendTemplateSMS = new SendTemplateSMS();
     $code = '';
     $charset = '1234567890';
     $_len = strlen($charset) - 1;
     for ($i = 0; $i < 6; ++$i) {
         $code .= $charset[mt_rand(0, $_len)];
     }
     $m3_result = $sendTemplateSMS->sendTemplateSMS($phone, array($code, 60), 1);
     if ($m3_result->status == 0) {
         $tempPhone = TempPhone::where('phone', $phone)->first();
         if ($tempPhone == null) {
             $tempPhone = new TempPhone();
         }
         $tempPhone->phone = $phone;
         $tempPhone->code = $code;
         $tempPhone->deadline = date('Y-m-d H-i-s', time() + 60 * 60);
         $tempPhone->save();
     }
     return $m3_result->toJson();
 }
コード例 #2
0
 public function getCategoryByParentId($parent_id)
 {
     $categorys = Category::where('parent_id', $parent_id)->get();
     $m3_result = new M3Result();
     $m3_result->status = 0;
     $m3_result->message = '返回成功';
     $m3_result->categorys = $categorys;
     return $m3_result->toJson();
 }
コード例 #3
0
 public function orderEdit(Request $request)
 {
     $order = Order::find($request->input('id', ''));
     $order->status = $request->input('status', 1);
     $order->save();
     $m3_result = new M3Result();
     $m3_result->status = 0;
     $m3_result->message = '添加成功';
     return $m3_result->toJson();
 }
コード例 #4
0
 public function memberEdit(Request $request)
 {
     $member = Member::find($request->input('id', ''));
     $member->nickname = $request->input('nickname', '');
     $member->phone = $request->input('phone', '');
     $member->email = $request->input('email', '');
     $member->save();
     $m3_result = new M3Result();
     $m3_result->status = 0;
     $m3_result->message = '添加成功';
     return $m3_result->toJson();
 }
コード例 #5
0
 /**
  * @brief 上传文件
  */
 public function uploadFile(Request $request, $type)
 {
     $width = $request->input("width", '');
     $height = $request->input("height", '');
     $m3_result = new M3Result();
     if ($_FILES["file"]["error"] > 0) {
         $m3_result->status = 2;
         $m3_result->message = "未知错误, 错误码: " . $_FILES["file"]["error"];
         return $m3_result->toJson();
     }
     $file_size = $_FILES["file"]["size"];
     if ($file_size > 1024 * 1024) {
         $m3_result->status = 2;
         $m3_result->message = "请注意图片上传大小不能超过1M";
         return $m3_result->toJson();
     }
     $public_dir = sprintf('/upload/%s/%s/', $type, date('Ymd'));
     $upload_dir = public_path() . $public_dir;
     if (!file_exists($upload_dir)) {
         mkdir($upload_dir, 0777, true);
     }
     // 获取文件扩展名
     $arr_ext = explode('.', $_FILES["file"]['name']);
     $file_ext = count($arr_ext) > 1 && strlen(end($arr_ext)) ? end($arr_ext) : "unknow";
     // 合成上传目标文件名
     $upload_filename = UUID::create();
     $upload_file_path = $upload_dir . $upload_filename . '.' . $file_ext;
     if (strlen($width) > 0) {
         $public_uri = $public_dir . $upload_filename . '.' . $file_ext;
         $m3_result->status = 0;
         $m3_result->message = "上传成功";
         $m3_result->uri = $public_uri;
     } else {
         // 从临时目标移到上传目录
         if (move_uploaded_file($_FILES["file"]["tmp_name"], $upload_file_path)) {
             $public_uri = $public_dir . $upload_filename . '.' . $file_ext;
             $m3_result->status = 0;
             $m3_result->message = "上传成功";
             $m3_result->uri = $public_uri;
         } else {
             $m3_result->status = 1;
             $m3_result->message = "上传失败, 权限不足";
         }
     }
     return $m3_result->toJson();
 }
コード例 #6
0
 public function categoryEdit(Request $request)
 {
     $id = $request->input('id', '');
     $category = Category::find($id);
     $name = $request->input('name', '');
     $category_no = $request->input('category_no', '');
     $parent_id = $request->input('parent_id', '');
     $preview = $request->input('preview', '');
     $category->name = $name;
     $category->category_no = $category_no;
     if ($parent_id != '') {
         $category->parent_id = $parent_id;
     }
     $category->preview = $preview;
     $category->save();
     $m3_result = new M3Result();
     $m3_result->status = 0;
     $m3_result->message = '添加成功';
     return $m3_result->toJson();
 }
コード例 #7
0
 public function login(Request $request)
 {
     $username = $request->input('username', '');
     $password = $request->input('password', '');
     $m3_result = new M3Result();
     if ($username == '' || $password == '') {
         $m3_result->status = 1;
         $m3_result->message = "帐号或密码不能为空!";
         return $m3_result->toJson();
     }
     $admin = Admin::where('username', $username)->where('password', md5('bk' . $password))->first();
     if (!$admin) {
         $m3_result->status = 2;
         $m3_result->message = "帐号或密码错误!";
     } else {
         $m3_result->status = 0;
         $m3_result->message = "登录成功!";
         $request->session()->put('admin', $admin);
     }
     return $m3_result->toJson();
 }
コード例 #8
0
 public function deleteCart(Request $request)
 {
     $m3_result = new M3Result();
     $m3_result->status = 0;
     $m3_result->message = '删除成功';
     $product_ids = $request->input('product_ids', '');
     if ($product_ids == '') {
         $m3_result->status = 1;
         $m3_result->message = '书籍ID为空';
         return $m3_result->toJson();
     }
     $product_ids_arr = explode(',', $product_ids);
     $member = $request->session()->get('member', '');
     if ($member != '') {
         // 已登录
         CartItem::whereIn('product_id', $product_ids_arr)->delete();
         return $m3_result->toJson();
     }
     $product_ids = $request->input('product_ids', '');
     if ($product_ids == '') {
         $m3_result->status = 1;
         $m3_result->message = '书籍ID为空';
         return $m3_result->toJson();
     }
     // 未登录
     $bk_cart = $request->cookie('bk_cart');
     $bk_cart_arr = $bk_cart != null ? explode(',', $bk_cart) : array();
     foreach ($bk_cart_arr as $key => $value) {
         $index = strpos($value, ':');
         $product_id = substr($value, 0, $index);
         // 存在, 删除
         if (in_array($product_id, $product_ids_arr)) {
             array_splice($bk_cart_arr, $key, 1);
             continue;
         }
     }
     return response($m3_result->toJson())->withCookie('bk_cart', implode(',', $bk_cart_arr));
 }
コード例 #9
0
 public function login(Request $request)
 {
     $username = $request->get('username', '');
     $password = $request->get('password', '');
     $validate_code = $request->get('validate_code', '');
     $m3_result = new M3Result();
     // 校验
     // ....
     // 判断
     // $validate_code_session = $request->session()->get('validate_code');
     // if($validate_code != $validate_code_session) {
     //   $m3_result->status = 1;
     //   $m3_result->message = '验证码不正确';
     //   return $m3_result->toJson();
     // }
     $member = null;
     if (strpos($username, '@') == true) {
         $member = Member::where('email', $username)->first();
     } else {
         $member = Member::where('phone', $username)->first();
     }
     if ($member == null) {
         $m3_result->status = 2;
         $m3_result->message = '该用户不存在';
         return $m3_result->toJson();
     } else {
         if (md5('bk' + $password) != $member->password) {
             $m3_result->status = 3;
             $m3_result->message = '密码不正确';
             return $m3_result->toJson();
         }
     }
     $request->session()->put('member', $member);
     $m3_result->status = 0;
     $m3_result->message = '登录成功';
     return $m3_result->toJson();
 }
コード例 #10
0
 public function productAdd(Request $request)
 {
     $name = $request->input('name', '');
     $summary = $request->input('summary', '');
     $price = $request->input('price', '');
     $category_id = $request->input('category_id', '');
     $preview = $request->input('preview', '');
     $content = $request->input('content', '');
     $preview1 = $request->input('preview1', '');
     $preview2 = $request->input('preview2', '');
     $preview3 = $request->input('preview3', '');
     $preview4 = $request->input('preview4', '');
     $preview5 = $request->input('preview5', '');
     $product = new Product();
     $product->summary = $summary;
     $product->price = $price;
     $product->category_id = $category_id;
     $product->preview = $preview;
     $product->name = $name;
     $product->save();
     $pdt_content = new PdtContent();
     $pdt_content->product_id = $product->id;
     $pdt_content->content = $content;
     $pdt_content->save();
     if ($preview1 != '') {
         $pdt_images = new PdtImages();
         $pdt_images->image_path = $preview1;
         $pdt_images->image_no = 1;
         $pdt_images->product_id = $product->id;
         $pdt_images->save();
     }
     if ($preview2 != '') {
         $pdt_images = new PdtImages();
         $pdt_images->image_path = $preview2;
         $pdt_images->image_no = 2;
         $pdt_images->product_id = $product->id;
         $pdt_images->save();
     }
     if ($preview3 != '') {
         $pdt_images = new PdtImages();
         $pdt_images->image_path = $preview3;
         $pdt_images->image_no = 3;
         $pdt_images->product_id = $product->id;
         $pdt_images->save();
     }
     if ($preview4 != '') {
         $pdt_images = new PdtImages();
         $pdt_images->image_path = $preview4;
         $pdt_images->image_no = 4;
         $pdt_images->product_id = $product->id;
         $pdt_images->save();
     }
     if ($preview5 != '') {
         $pdt_images = new PdtImages();
         $pdt_images->image_path = $preview5;
         $pdt_images->image_no = 5;
         $pdt_images->product_id = $product->id;
         $pdt_images->save();
     }
     $m3_result = new M3Result();
     $m3_result->status = 0;
     $m3_result->message = '添加成功';
     return $m3_result->toJson();
 }