Esempio n. 1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function copyTrend(Request $request)
 {
     Log::info("copyTrend");
     $id = request('ZZ');
     $trend_name = request('trend_name');
     $target_group = request('target_group');
     $target_unit = request('target_unit');
     Log::info("ZZ[" . $id . "],trend_name[" . $trend_name . "],target_group[" . $target_group . "]\n        target_unit[" . $target_unit . "]");
     if ($target_group == '9') {
         $target_group = Auth::user()->empId;
     }
     $isExcessTrend = false;
     $maxTrend = 0;
     $count = 0;
     $user_priority = session()->get('user_priority');
     if (request('target_group') == '9') {
         $countMyTrend = DB::connection(DBUtils::getDBName())->table('mmname_table')->where('B', '=', $target_group)->count();
         if ($user_priority < 128) {
             $isExcessTrend = $countMyTrend > 3;
             $maxTrend = 4;
         } else {
             if ($user_priority < 201) {
                 $isExcessTrend = $countMyTrend > 48;
                 $maxTrend = 49;
             } else {
                 if ($user_priority < 255) {
                     $isExcessTrend = $countMyTrend > 98;
                     $maxTrend = 99;
                 } else {
                     $isExcessTrend = $countMyTrend > 9998;
                     $maxTrend = 9999;
                 }
             }
         }
     }
     $mmtrendM = MmnameModel::on(DBUtils::getDBName())->find($id);
     if (!empty($mmtrendM) && !$isExcessTrend) {
         // set target group
         $count = DB::connection(DBUtils::getDBName())->table('mmname_table')->where('A', '=', $trend_name)->where('B', '=', $target_group)->count();
         if ($count == 0) {
             $mmtrendM_new = new MmnameModel();
             $mmtrendM_new->setConnection(DBUtils::getDBName());
             $mmtrendM_new->A = $trend_name;
             if ($target_group == '9') {
                 $mmtrendM_new->B = Auth::user()->empId;
             } else {
                 $mmtrendM_new->B = $target_group;
             }
             $mmtrendM_new->save();
             $mmtrends = MmtrendModel::on(DBUtils::getDBName())->where('G', $id)->get();
             if (!empty($mmtrends)) {
                 foreach ($mmtrends as $mmtrend) {
                     $mmtrendModel_new = new MmtrendModel();
                     $mmtrendModel_new->setConnection(DBUtils::getDBName());
                     $mmtrendModel_new->A = $mmtrend->A;
                     if ($target_unit == '0') {
                         $mmtrendModel_new->B = $mmtrend->B;
                     } else {
                         $mmtrendModel_new->B = $target_unit;
                     }
                     $mmtrendModel_new->C = $mmtrend->C;
                     $mmtrendModel_new->D = $mmtrend->D;
                     $mmtrendModel_new->E = $mmtrend->E;
                     $mmtrendModel_new->F0 = $mmtrend->F0;
                     $mmtrendModel_new->F1 = $mmtrend->F1;
                     $mmtrendModel_new->H = $mmtrend->H;
                     $mmtrendModel_new->I = $mmtrend->I;
                     $mmtrendModel_new->G = $mmtrendM_new->ZZ;
                     $mmtrendModel_new->save();
                 }
             }
         }
     }
     Log::info("mmnameModel ->" . $mmtrendM->A);
     return response()->json(['mmtrendM' => json_encode($mmtrendM), 'count' => json_encode($count), 'isExcessTrend' => json_encode($isExcessTrend), 'maxTrend' => json_encode($maxTrend)]);
 }