Exemplo n.º 1
0
 /**
  * Пересчитывает даты начала и окончания закрепления по операции
  * @param type $operation
  * @param type $uid
  * @return type
  */
 private function recalcBindDates($operation, $uid)
 {
     //Получаем коды операций, которые могли быть применены по данному закреплению
     $op_codes_allow = array();
     foreach ($this->op_code_groups as $group) {
         $op_codes_in_group = billing::extendOpCodes($group);
         if (in_array($operation['op_code'], $op_codes_in_group)) {
             $op_codes_allow = $op_codes_in_group;
         }
     }
     //Получаем информацию об остальных платежах по данному закреплению
     $sql2 = "SELECT bq.op_code, bq.op_count, br.complete_time::timestamp as date\n            FROM bill_queue bq\n            INNER JOIN bill_reserve br ON bq.reserve_id = br.id\n            INNER JOIN account_operations ao ON br.ammount = -(ao.ammount) \n                AND br.complete_time::timestamp = ao.op_date::timestamp\n                AND ao.billing_id = (SELECT id FROM account WHERE uid = ?i)\n            WHERE bq.uid = ?i AND bq.service IN ('frlbind', 'frlbindup')\n                AND bq.src_id = ?i AND bq.op_code IN (?l)\n                AND bq.status = 'complete' AND bq.id != ?i\n            ORDER BY br.complete_time ASC;";
     $operations = $this->db->rows($sql2, $uid, $uid, $operation['src_id'], $op_codes_allow, $operation['id']);
     foreach ($operations as $operation) {
         //Устанавливаем даты начала при любой операции
         $date_start = DateTime::createFromFormat("Y-m-d H:i:s.u", $operation['date']);
         $operation['op_code'] = billing::getOpCodeByDiscount($operation['op_code']);
         if (in_array($operation['op_code'], array(self::OP_CODE_CATALOG, self::OP_CODE_PROFGROUP, self::OP_CODE_PROF)) || !isset($date_stop)) {
             //Если покупка, то дату окончания считаем от даты покупки
             $date_stop = clone $date_start;
             $date_stop->add(new DateInterval('P' . $operation['op_count'] * 7 . 'D'));
         } else {
             //Если продление - продляем дату окончания
             if (in_array($operation['op_code'], array(self::OP_CODE_PROLONG_CATALOG, self::OP_CODE_PROLONG_PROFGROUP, self::OP_CODE_PROLONG_PROF))) {
                 $date_stop->add(new DateInterval('P' . $operation['op_count'] * 7 . 'D'));
             }
         }
     }
     if (!isset($date_start)) {
         $date_start = new DateTime('NOW');
     }
     if (!isset($date_stop)) {
         $date_stop = clone $date_start;
     }
     return array('start' => $date_start->format('Y-m-d H:i:s'), 'stop' => $date_stop->format('Y-m-d H:i:s'));
 }
Exemplo n.º 2
0
 /**
  * Пересчитывает даты начала и окончания закрепления по операции.
  *
  * @param int   $uid
  * @param array $params
  *
  * @return type
  */
 private function recalcBindDates($uid, $params)
 {
     //Получаем коды операций, которые могли быть применены по данному закреплению
     $op_codes_allow = array();
     foreach ($this->op_codes_groups as $group) {
         $op_codes_in_group = billing::extendOpCodes($group);
         if (in_array($params['op_code'], $op_codes_in_group)) {
             $op_codes_allow = $op_codes_in_group;
         }
     }
     //Получаем информацию об остальных платежах по данному закреплению
     $sql2 = "SELECT bq.op_code, bq.op_count, bq.src_id, bq.option, bq.service, br.complete_time::timestamp as date\n            FROM bill_queue bq\n            INNER JOIN bill_reserve br ON bq.reserve_id = br.id\n            INNER JOIN account_operations ao ON br.ammount = -(ao.ammount) \n                AND br.complete_time::timestamp = ao.op_date::timestamp\n                AND ao.billing_id = (SELECT id FROM account WHERE uid = ?i)\n            WHERE bq.uid = ?i AND bq.op_code IN (?l)\n                AND ((bq.service = 'tservicebind' AND bq.src_id = ?i) OR (bq.service = 'tservicebindup' AND bq.src_id = ?i))\n                AND bq.status = 'complete' AND bq.id != ?i\n            ORDER BY br.complete_time ASC;";
     $operations = $this->db()->rows($sql2, $uid, $uid, $op_codes_allow, $params['prof_id'], $params['bind_id'], $params['op_id']);
     foreach ($operations as $operation) {
         $is_prolong = $is_up = false;
         //Устанавливаем даты начала при любой операции
         $date_start = DateTime::createFromFormat('Y-m-d H:i:s.u', $operation['date']);
         if ($operation['service'] == 'tservicebind') {
             $options = mb_unserialize($operation['option']);
             if ($options['tservice_id'] != $params['tservice_id']) {
                 continue;
             }
             $is_prolong = $options['is_prolong'];
         } else {
             $is_up = true;
         }
         if (!$is_prolong && !$is_up || !isset($date_stop)) {
             //Если покупка, то дату окончания считаем от даты покупки
             $date_stop = clone $date_start;
             $date_stop->add(new DateInterval('P' . $operation['op_count'] * 7 . 'D'));
         } elseif ($is_prolong) {
             //Если продление - продляем дату окончания
             $date_stop->add(new DateInterval('P' . $operation['op_count'] * 7 . 'D'));
         }
     }
     if (!isset($date_stop)) {
         $date_stop = clone $date_start;
     }
     return array('start' => $date_start->format('Y-m-d H:i:s'), 'stop' => $date_stop->format('Y-m-d H:i:s'));
 }