/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('booths', function ($table) {
         $table->integer('pv_id');
         // 省id
     });
     Schema::table('crowd_fundings', function ($table) {
         $table->integer('pv_id');
         // 省id
     });
     Schema::table('promotion_infos', function ($table) {
         $table->integer('pv_id');
     });
     $list = Booth::with(['school'])->get();
     foreach ($list as $key => $booth) {
         $pv_id = $booth->school->t_province;
         $booth->pv_id = $pv_id;
         $booth->save();
     }
     $list = CrowdFunding::with(['school'])->get();
     foreach ($list as $key => $funding) {
         $pv_id = $funding->school->t_province;
         $funding->pv_id = $pv_id;
         $funding->save();
     }
     $list = PromotionInfo::with(['school'])->get();
     foreach ($list as $key => $promo) {
         $pv_id = $promo->school->t_province;
         $promo->pv_id = $pv_id;
         $promo->save();
     }
 }
 public function listSellCrowdFunding()
 {
     $per_page = Input::get('per_page', 30);
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $filter_option = Input::get('filter_option', 0);
     try {
         $now = Tools::getNow();
         $user = User::chkUserByToken($token, $u_id);
         $query = CrowdFunding::with(['city', 'school', 'user', 'product', 'eventItem', 'praises' => function ($q) {
             $q->where('praises.u_id', '=', $this->u_id);
         }])->join('event_items', function ($q) {
             $q->on('event_items.e_id', '=', 'crowd_fundings.e_id');
         })->where('crowd_fundings.u_id', '=', $u_id);
         switch ($filter_option) {
             case 1:
                 $query = $query->where('crowd_fundings.c_status', '=', 1);
                 break;
             case 2:
                 $query = $query->where('crowd_fundings.c_status', '=', 2);
                 break;
             case 3:
                 $query = $query->where('event_items.e_start_at', '>', $now);
                 break;
             case 4:
                 $query = $query->where('crowd_fundings.c_status', '=', 4);
                 break;
             case 5:
                 $query = $query->where('crowd_fundings.c_status', '=', 5);
                 break;
             case 6:
                 $query = $query->where('crowd_fundings.c_status', '=', 3);
                 break;
             default:
                 break;
         }
         $list = $query->orderBy('crowd_fundings.created_at', 'DESC')->paginate($per_page);
         $data = [];
         foreach ($list as $key => $funding) {
             $tmp = $funding->showInList();
             $tmp['is_praised'] = 0;
             if (count($funding->praises) > 0) {
                 $tmp['is_praised'] = 1;
             }
             $data[] = $tmp;
         }
         $re = Tools::reTrue('获取众筹成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取众筹失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function listFunding()
 {
     $per_page = Input::get('per_page', 30);
     $filter_option = Input::get('filter_option', 0);
     try {
         $query = CrowdFunding::with('product', 'eventItem');
         if ($filter_option == 1) {
             $query = $query->where('c_cate', '=', 8);
         }
         $list = $query->paginate($per_page);
         $data['rows'] = [];
         foreach ($list as $key => $funding) {
             $data['rows'][] = $funding->showInList();
         }
         $data['total'] = $list->getTotal();
         $re = Tools::reTrue('获取众筹列表成功', $data, $list);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取众筹列表失败:' . $e->getMessage());
     }
     return Response::json($re);
 }