Ejemplo n.º 1
0
 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}");
 }
Ejemplo n.º 2
0
 public function getOrderInfoCount()
 {
     $sql = "select * from " . MOrder::tableName() . " where gh_id='" . $this->gh_id . "' and openid='" . $this->openid . "' and (status =" . MOrder::STATUS_SUBMITTED . " or status =" . MOrder::STATUS_PAID . " or status =" . MOrder::STATUS_FULFILLED . ") and create_time > DATE_SUB(NOW(), INTERVAL 1 month) order by create_time DESC";
     return count(Morder::findBySql($sql)->all());
     //        return $this->hasMany(MOrder::className(), ['gh_id'=>'gh_id', 'openid'=>'openid']);
 }