public function run()
 {
     $user_id = Input::get('user_id', 0);
     $album_id = Input::get('album_id', 0);
     $user = UserORM::whereId($user_id)->whereStatus(BaseORM::ENABLE)->first();
     if (empty($user)) {
         return '用户未找到';
     }
     $album = AlbumORM::whereId($album_id)->whereUserId($user_id)->first();
     if (empty($album)) {
         return '相册未找到';
     }
     $sources = AlbumSourceORM::whereAlbumId($album_id)->orderBy('is_front', 'DESC')->get();
     $template_source_count = TemplateSourceORM::whereTemplateId($album->template_id)->count();
     $images = [];
     foreach ($sources as $s) {
         $tmp = [];
         $tmp['id'] = $s->id;
         $tmp['album_id'] = $s->album_id;
         $tmp['source'] = Config::get('app.image_host') . $s->source;
         $tmp['is_front'] = $s->is_front;
         $images[] = $tmp;
     }
     $can_add = 0;
     if ($template_source_count > count($sources)) {
         $can_add = 1;
     }
     return ['album' => $album, 'images' => $images, 'can_add' => $can_add];
 }
 public function run()
 {
     $user_id = Input::get('user_id', 0);
     $user = UserORM::whereId($user_id)->first();
     if (empty($user)) {
         return '用户未找到';
     }
     return $user;
 }
 public function run()
 {
     $user_id = intval(Input::get('user_id', 0));
     $user = UserORM::find($user_id);
     if (empty($user)) {
         return '用户未找到';
     }
     $sql = "SELECT a.*, al.source FROM album as a LEFT JOIN album_source as al ON al.album_id = a.id WHERE a.user_id = " . $user_id . " AND al.is_front = " . BaseORM::ENABLE . "  ORDER BY a.id DESC";
     $results = DB::select(DB::raw($sql));
     return AlbumModel::listData($results);
 }
 public function run()
 {
     $user_id = intval(Input::get('user_id', 0));
     $album_id = intval(Input::get('album_id', 0));
     $quantity = intval(Input::get('quantity', 1));
     $real_name = trim(Input::get('real_name', ''));
     $mobile = trim(Input::get('mobile', ''));
     $address = trim(Input::get('address', ''));
     if (empty($real_name)) {
         return '姓名必须填写';
     }
     if (empty($mobile)) {
         return '联系电话必须填写';
     }
     if (empty($address)) {
         return '联系地址必须填写';
     }
     $user = UserORM::whereId($user_id)->whereStatus(BaseORM::ENABLE)->first();
     if (empty($user)) {
         return '用户未找到';
     }
     $album = AlbumORM::whereId($album_id)->whereUserId($user_id)->first();
     if (empty($album)) {
         return '相册未找到';
     }
     $source = AlbumSourceORM::whereAlbumId($album_id)->get();
     if (count($source) == 0) {
         return '该相册没有任何图片';
     }
     $template = TemplateORM::whereId($album->template_id)->first();
     if (empty($template)) {
         return '相册模版未找到';
     }
     if (intval($quantity) <= 0) {
         return '数量错误';
     }
     $price = $template->price;
     $total_amount = $price * $quantity;
     $orm = new OrderORM();
     $orm->user_id = $user_id;
     $orm->album_id = $album_id;
     $orm->quantity = $quantity;
     $orm->total_amount = $total_amount;
     $orm->save();
     $order = OrderORM::find($orm->id);
     $user->real_name = $real_name;
     $user->mobile = $mobile;
     $user->address = $address;
     $user->save();
     return $order;
 }
 public function show()
 {
     $id = (int) Input::get('id', 0);
     $album = AlbumORM::find($id);
     if ($id > 0 && empty($album)) {
         Session::flash('error', '相册未找到');
         return Redirect::route('albumLists');
     }
     $sources = AlbumSourceORM::whereAlbumId($id)->get();
     $classes = TemplateClassORM::all();
     array_ch_key('id', $classes);
     $format_classes = array_ch_key('id', $classes);
     $user = UserORM::find($album->user_id);
     return View::make('album.show', ['row' => $album, 'user' => $user, 'source' => $sources, 'classes' => $format_classes]);
 }
 public function show()
 {
     $id = (int) Input::get('id', 0);
     $order = OrderORM::find($id);
     if ($id > 0 && empty($order)) {
         Session::flash('error', '订单未找到');
         return Redirect::route('orderLists');
     }
     $user = UserORM::whereId($order->user_id)->first();
     $album = AlbumORM::whereId($order->album_id)->first();
     $template = TemplateORM::whereId($album->template_id)->first();
     $template_class = TemplateClassORM::whereId($template->class)->first();
     $source = AlbumSourceORM::whereAlbumId($album->id)->get();
     return View::make('order.show', ['row' => $order, 'user' => $user, 'album' => $album, 'template' => $template, 'class' => $template_class, 'source' => $source, 'id' => $id]);
 }
 public function run()
 {
     $open_id = Input::get('wx_id', '');
     $user = [];
     if (!empty($open_id)) {
         $tmpUser = UserORM::whereWxId($open_id)->first();
         if ($tmpUser) {
             $user = $tmpUser;
         } else {
             $id = 0;
             $params = ['wx_id' => $open_id];
             $r = UserORM::edit($id, $params);
             $user = UserORM::find($r[1]->id);
         }
     }
     return $user;
 }
 public function run()
 {
     $user_id = Input::get('user_id', 0);
     $class_id = Input::get('class_id', 0);
     $template_id = Input::get('template_id', 0);
     $user = UserORM::whereId($user_id)->whereStatus(BaseORM::ENABLE)->first();
     if (empty($user)) {
         return '用户未找到';
     }
     $class = TemplateClassORM::whereId($class_id)->whereStatus(BaseORM::ENABLE)->first();
     if (empty($class)) {
         return '相册分类未找到';
     }
     $template = TemplateORM::whereId($template_id)->whereClass($class_id)->whereStatus(BaseORM::ENABLE)->first();
     if (empty($template)) {
         return '模版未找到';
     }
     $r = AlbumORM::edit(0, ['user_id' => $user_id, 'class' => $class_id, 'template_id' => $template_id]);
     return $r[1];
 }
 public function save()
 {
     $id = (int) Input::get('id', 0);
     $params = Input::all();
     unset($params['id']);
     if (empty($params['real_name'])) {
         $this->_fail('姓名必填');
     }
     if (empty($params['mobile'])) {
         $this->_fail('电话必填');
     }
     if (empty($params['address'])) {
         $this->_fail('地址必填');
     }
     try {
         UserORM::edit($id, $params);
         $this->_succ('保存成功', URL::route('userLists'));
     } catch (Exception $e) {
         $this->_fail('保存失败');
     }
 }