public function actionUpdate($id) { $model = MOrder::findOne($id); if (!$model) { throw new NotFoundHttpException('no this order'); } if (\Yii::$app->request->isPost) { $model->load(\Yii::$app->request->post()); if ($model->save(true, ['status', 'select_mobnum', 'memo_reply', 'wlgs', 'wldh'])) { $mobnum = MMobnum::findOne($model->select_mobnum); if ($mobnum !== null) { if ($model->status == MOrder::STATUS_SUCCEEDED) { $mobnum->status = MMobnum::STATUS_USED; } else { if ($model->status == MOrder::STATUS_SUBMITTED) { $mobnum->status = MMobnum::STATUS_LOCKED; } else { if ($model->status == MOrder::STATUS_BUYER_CLOSED) { $mobnum->status = MMobnum::STATUS_UNUSED; } } } $mobnum->save(false); } //会员(非自营厅渠道的)下单成功 STATUS_SUCCEEDED/STATUS_SYSTEM_SUCCEEDED时,非自营厅渠道要 +积分100 $user = MUser::findOne(['openid' => $model->openid]); $office = MOffice::findOne(['office_id' => $user->belongto]); if ($office->is_selfOperated == 0) { if ($model->status == MOrder::STATUS_SUCCEEDED) { //wx_office_score_event 增加一条记录 $offce_score_event = new MOfficeScoreEvent(); $offce_score_event->gh_id = $model->gh_id; $offce_score_event->openid = $model->openid; $offce_score_event->office_id = $user->belongto; $offce_score_event->cat = MOfficeScoreEvent::CAT_ADD_ORDER; $offce_score_event->create_time = date('y-m-d h:i:s', time()); $offce_score_event->score = MOfficeScoreEvent::CAT_ADD_ORDER_SCORE; $offce_score_event->memo = '会员订单'; $offce_score_event->save(false); //wx_office表中对应渠道score 加100分 $office->score = $office->score + 100; $office->save(false); } } return $this->redirect(['index']); } } return $this->render('update', ['model' => $model]); }
public function actionImportMobilenum() { /* $pattern = "/(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\d/"; //$ret = preg_match($pattern, '123456789'); $ret = preg_match($pattern, 'a234567b6789'); if ($ret) echo 'match'; else echo 'no match'; */ $num_cat = MMobnum::getNumCat(MItem::ITEM_CAT_MOBILE_IPHONE4S); $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'mobile_num.txt'; $fh = fopen($file, "r"); $i = 0; $sm_valid_cids = array(); while (!feof($fh)) { $line = fgets($fh); if (empty($line)) { continue; } $mobnum = trim($line); $ychf = 0; $zdxf = 0; $is_good = 1; $tableName = MMobnum::tableName(); $n = Yii::$app->db->createCommand("REPLACE INTO {$tableName} (num, num_cat, ychf, zdxf, is_good) VALUES (:num, :num_cat, :ychf, :zdxf, :is_good)", [':num' => $mobnum, ':num_cat' => $num_cat, ':ychf' => $ychf, ':zdxf' => $zdxf, ':is_good' => $is_good])->execute(); $i++; //if ($i > 2) break; } fclose($fh); }
public static function closeExpiredOrders() { $tableName = MOrder::tableName(); $n = Yii::$app->db->createCommand()->delete($tableName, 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_DRAFT])->execute(); U::W("UPDATE {$tableName}, {$n} --- 系统删除2天前的僵死订单。"); // auto close the orders exceed 2 days $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MOrder::STATUS_SYSTEM_CLOSED], 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_SUBMITTED])->execute(); U::W("UPDATE {$tableName}, {$n} --- 系统自动关闭超时2天的提交订单。"); $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MOrder::STATUS_SYSTEM_SUCCEEDED], 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_FULFILLED])->execute(); U::W("UPDATE {$tableName}, {$n} --- 系统自动确认超时2天的已办理订单。"); //找到超时2天的成功订单, 将其归属的渠道 +积分100 $orders = MOrder::find()->where(['status' => MOrder::STATUS_FULFILLED])->andWhere(['<', 'create_time', 'DATE_SUB(NOW(), INTERVAL 2 day)'])->all(); foreach ($orders as $order) { $user = MUser::findOne(['openid' => $order->openid]); $office = MOffice::findOne(['office_id' => $user->belongto]); if ($office->is_selfOperated == 0) { //wx_office_score_event 增加一条记录 $offce_score_event = new MOfficeScoreEvent(); $offce_score_event->gh_id = $order->gh_id; $offce_score_event->openid = $order->openid; $offce_score_event->office_id = $user->belongto; $offce_score_event->cat = MOfficeScoreEvent::CAT_ADD_ORDER; $offce_score_event->create_time = date('y-m-d h:i:s', time()); $offce_score_event->score = MOfficeScoreEvent::CAT_ADD_ORDER_SCORE; $offce_score_event->memo = '会员订单'; $offce_score_event->save(false); //wx_office表中对应渠道score 加100分 $office->score = $office->score + 100; $office->save(false); } } /* //move the unsuccessful orders exceed 90 days to bak table $n = Yii::$app->db->createCommand("INSERT INTO {$tableName}_arc SELECT * FROM $tableName WHERE status!=:status AND create_time < DATE_SUB(NOW(), INTERVAL 90 day)", [':status'=>MOrder::STATUS_OK])->execute(); U::W("INSERT $tableName, $n"); $n = Yii::$app->db->createCommand("DELETE FROM $tableName WHERE status!=:status AND create_time < DATE_SUB(NOW(), INTERVAL 90 day)", [':status'=>MOrder::STATUS_OK])->execute(); U::W("DELETE $tableName, $n"); */ //release mobile number $tableName = MMobnum::tableName(); $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MMobnum::STATUS_UNUSED, 'locktime' => 0], 'status=:status AND locktime < :locktime', [':status' => MMobnum::STATUS_LOCKED, ':locktime' => time() - 2 * 24 * 3600])->execute(); U::W("UPDATE {$tableName}, {$n}"); $n = Yii::$app->db->createCommand("DELETE FROM {$tableName} WHERE status=:status", [':status' => MMobnum::STATUS_USED])->execute(); U::W("DELETE {$tableName}, {$n}"); }
public function actionAjaxdata($cat) { //if (!Yii::$app->request->isAjax) // return; $this->layout = false; switch ($cat) { case 'orderclose': $oid = isset($_GET["oid"]) ? $_GET["oid"] : 1; $model = MOrder::findOne($oid); if ($model === null) { U::D(["invalid oid:{$oid}", __METHOD__]); } $model->status = MOrder::STATUS_BUYER_CLOSED; if ($model->save(true, ['status'])) { $mobnum = MMobnum::findOne($model->select_mobnum); if ($mobnum !== null) { $mobnum->status = MMobnum::STATUS_UNUSED; $mobnum->save(false); } $data['code'] = 0; } else { return json_encode(['code' => 1, 'errmsg' => 'save db error']); } break; case 'orderview': $oid = isset($_GET["oid"]) ? $_GET["oid"] : 1; $data = MOrder::find()->select('*')->where("oid=:oid", [':oid' => $oid])->asArray()->one(); $data['statusName'] = MOrder::getOrderStatusName($data['status']); $order = MOrder::findOne($oid); if ($order->status == MOrder::STATUS_SUBMITTED) { $jsApiParameters = $order->GetOrderJsApiParameters(); $data['url'] = $jsApiParameters; } else { $data['url'] = ''; } break; case 'myorder': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); $page = isset($_GET["currentPage"]) ? $_GET["currentPage"] : 1; $size = isset($_GET['size']) ? $_GET['size'] : 8; $data = MOrder::find()->select('*')->where("gh_id=:gh_id AND openid=:openid AND status!=:status", [':gh_id' => $gh_id, ':openid' => $openid, ':status' => MOrder::STATUS_DRAFT])->orderBy(['oid' => SORT_DESC])->offset(($page - 1) * $size)->limit($size)->asArray()->all(); foreach ($data as &$row) { $row['statusName'] = MOrder::getOrderStatusName($row['status']); } unset($row); break; case 'officeorder': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); $page = isset($_GET["currentPage"]) ? $_GET["currentPage"] : 1; $size = isset($_GET['size']) ? $_GET['size'] : 8; $orderby = isset($_GET["orderby"]) ? $_GET["orderby"] : 'oid'; $asc = isset($_GET["asc"]) ? $_GET["asc"] : 0; $office_id = isset($_GET["office_id"]) ? $_GET["office_id"] : 0; $data = MOrder::find()->select('*')->where("gh_id=:gh_id AND office_id=:office_id", [':gh_id' => $gh_id, ':office_id' => $office_id])->orderBy([$orderby => $asc == 1 ? SORT_ASC : SORT_DESC])->offset(($page - 1) * $size)->limit($size)->asArray()->all(); foreach ($data as &$row) { $row['statusName'] = MOrder::getOrderStatusName($row['status']); } unset($row); break; case 'mobileNum': $page = isset($_GET["currentPage"]) ? $_GET["currentPage"] : 1; $size = isset($_GET['size']) ? $_GET['size'] : 8; $feeSum = isset($_GET['feeSum']) ? $_GET['feeSum'] : 100000; $feeSum = $feeSum * 100; $cid = isset($_GET["cid"]) ? $_GET["cid"] : MItem::ITEM_CAT_DIY; $num_cat = MMobnum::getNumCat($cid); $data = MMobnum::find()->select('num,ychf,zdxf')->where("status=:status AND num_cat=:num_cat AND zdxf <= :zdxf", [':status' => MMobnum::STATUS_UNUSED, ':num_cat' => $num_cat, ':zdxf' => $feeSum])->offset(($page - 1) * $size)->limit($size)->asArray()->all(); break; case 'diskclick': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); $model = MDisk::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if ($model === null) { $model = MDisk::initDefault($gh_id, $openid); } else { if ($model->cnt > 0) { $model->cnt = $model->cnt - 1; } else { return json_encode(['code' => 1, 'errmsg' => 'has no qualification']); } } $data = U::makeDiskResult(); if ($data['code'] == 0) { if ($data['value'] % 2 == 0) { $model->cnt = 0; $model->win = 1; $model->win_time = time(); } } $model->save(false); break; case 'diskRestCnt': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); $model = MDisk::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if ($model === null) { $model = MDisk::initDefault($gh_id, $openid); $model->save(false); $model = MDisk::findOne(['gh_id' => $gh_id, 'openid' => $openid]); } $data = $model->getAttributes(); $cur_time = time(); if ($model->win == 1 && $cur_time - $model->win_time < 30 * 60) { $alreadyWin = 1; } else { $alreadyWin = 0; } $data['alreadyWin'] = $alreadyWin; $data['code'] = 0; break; case 'g2048Save': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); Yii::$app->wx->setGhId($gh_id); $user = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if ($user === null) { $user = new MUser(); } if (!empty($user->subscribe)) { $model = new \app\models\MG2048(); $model->gh_id = $gh_id; $model->openid = $openid; $model->best = $_GET['best']; $model->score = $_GET['score']; $model->big_num = $_GET['bigNum']; if (!$model->save(false)) { U::W([__METHOD__, $model->getErrors()]); return json_encode(['code' => 1, 'errmsg' => 'save score to db error']); } } $data['code'] = 0; $data['isSubscribed'] = empty($user->subscribe) ? 0 : 1; $data['position'] = MG2048::getCurrentScorePosition($gh_id, $_GET['score']); break; case 'getnearestoffice': $gh_id = U::getSessionParam('gh_id'); $lat = $_GET["lat"]; $lon = $_GET["lon"]; $rows = MOffice::getNearestOffices($gh_id, $lon, $lat); U::W($rows); $data['code'] = 0; $data['offices'] = $rows; break; case 'pkginfo': $gh_id = U::getSessionParam('gh_id'); $cid = isset($_GET["cid"]) ? $_GET["cid"] : MItem::ITEM_CAT_MOBILE_APPLE_5S_32G_SILVER; $pkg3g4g = isset($_GET["pkg3g4g"]) ? $_GET["pkg3g4g"] : ''; $period = isset($_GET["pkgPeriod"]) ? $_GET["pkgPeriod"] : 12; $monthprice = isset($_GET["pkgMonthprice"]) ? $_GET["pkgMonthprice"] : 46; $plan = $_GET["pkgPlan"] == 'null' ? '' : $_GET["pkgPlan"]; //$data = MPkg::find()->select('*')->where( // "gh_id=:gh_id AND cid=:cid AND pkg3g4g=:pkg3g4g AND period=:period AND monthprice=:monthprice AND plan=:plan", // [':gh_id'=>$gh_id, ':cid'=>$cid, ':pkg3g4g'=>$pkg3g4g, ':period'=>$period, ':monthprice'=>$monthprice, ':plan'=>$plan])->asArray()->one(); $data = MPkg::find()->select('*')->where("gh_id=:gh_id AND cid=:cid AND pkg3g4g=:pkg3g4g AND period=:period AND monthprice=:monthprice", [':gh_id' => $gh_id, ':cid' => $cid, ':pkg3g4g' => $pkg3g4g, ':period' => $period, ':monthprice' => $monthprice])->asArray()->one(); //foreach($data as &$row) //{ // $row['statusName'] = MOrder::getOrderStatusName($row['status']); //} //unset($row); break; case 'wlinfo': U::W("++++++++++++++++++++++++++++++++++++++"); $wl_url_1 = isset($_GET["wl_url_1"]) ? $_GET["wl_url_1"] : ''; $wl_url_2 = isset($_GET["wl_url_2"]) ? $_GET["wl_url_2"] : ''; $wl_url = "http://www.kuaidi100.com/query?type=" . $wl_url_1 . "&postid=" . $wl_url_2; //U::W($wl_url); $data = file_get_contents($wl_url); //$data = substr($lucy_msg, 14, -2); $data = json_decode($data, true); //U::W($data); break; case 'woketixian': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); U::W("----------assdfsdf1-----------"); U::W($openid); Yii::$app->wx->setGhId($gh_id); $user = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); $model = new \app\models\MSceneDetail(); $model->gh_id = $gh_id; $model->openid = $openid; $model->scene_id = $user->scene_id; $model->scene_amt = -1 * $_GET['ljtx']; $model->memo = $_GET['memo']; $model->czhm = $_GET['czhm']; if (!$model->save(false)) { U::W([__METHOD__, $model->getErrors()]); return json_encode(['code' => 1, 'errmsg' => 'save score to db error']); } $user->scene_balance = $user->scene_balance - abs($model->scene_amt); if (!$user->save(false)) { U::W([__METHOD__, $model->getErrors()]); return json_encode(['code' => 1, 'errmsg' => 'save score to db error']); } $data['ljtx'] = abs($model->scene_amt); break; case 'wokeqdyl': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); U::W("----------wokeqdyl-----------"); U::W($openid); Yii::$app->wx->setGhId($gh_id); $user = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); U::W("\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$"); U::W($user); $model = new \app\models\MSceneDetail(); $model->gh_id = $gh_id; $model->openid = $openid; $model->scene_id = $user->scene_id; $money_max = 8; //每日签到有礼,8个沃点封顶; if ($user->sign_money == 0) { $user->sign_time = date("Y-m-d"); $user->sign_money = 1; } else { if (strtotime(date("Y-m-d")) - strtotime($user->sign_time) < 1) { //$user->sign_time = date("Y-m-d"); //$user->sign_money = 1; $data['sign_money'] = 'marked'; break; } else { if ((strtotime(date("Y-m-d")) - strtotime($user->sign_time)) / 86400 > 1) { $user->sign_time = date("Y-m-d"); $user->sign_money = 1; } else { $user->sign_time = date("Y-m-d"); $user->sign_money = 2 * $user->sign_money > $money_max ? $money_max : 2 * $user->sign_money; } } } $model->scene_amt = $user->sign_money; $model->memo = $_GET['memo']; $model->cat = MSceneDetail::CAT_SIGN; if (!$model->save(false)) { U::W([__METHOD__, $model->getErrors()]); return json_encode(['code' => 1, 'errmsg' => 'save score to db error']); } //$user->scene_balance = $user->scene_balance + abs($model->scene_amt); if (!$user->save(false)) { U::W([__METHOD__, $model->getErrors()]); return json_encode(['code' => 1, 'errmsg' => 'save score to db error']); } $data['sign_money'] = $user->sign_money; break; case 'czsjhm': $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); Yii::$app->wx->setGhId($gh_id); $user = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if ($user === null) { $user = new MUser(); } if (!empty($user->subscribe)) { $user->gh_id = $gh_id; $user->openid = $openid; $user->user_account_charge_mobile = $_GET['czhm1']; if (!$user->save(false)) { U::W([__METHOD__, $user->getErrors()]); return json_encode(['code' => 1, 'errmsg' => 'save score to db error']); } } $data['czsjhm'] = $user->user_account_charge_mobile; break; default: U::W(['invalid data cat', $cat, __METHOD__, $_GET]); return; } U::W([$data]); U::W(json_encode($data)); return json_encode($data); }