コード例 #1
0
ファイル: IProductBase.php プロジェクト: songhongyu/idaiyan
 public function choose($uid, $type = 0, $stat = 0, $order = 0)
 {
     if (isset($uid)) {
         //状态筛选条件
         $typeMap = ['2' => self::STATUS_VERIFING, '3' => self::STATUS_VERIFIED, '4' => self::STATUS_VERIFEND, '5' => self::STATUS_FIRST, '6' => self::STATUS_NOTHROUGH];
         if (in_array($type, array_keys($typeMap))) {
             $conditions = [self::tableName() . '.status' => $type];
         } else {
             $conditions = [];
         }
         $activeMap = ['1' => ProductStat::tableName() . '.has_unstart_activity', '2' => ProductStat::tableName() . '.has_started_activity', '3' => ProductStat::tableName() . '.has_ended_activity'];
         if (in_array($stat, array_keys($activeMap))) {
             $conditions[$activeMap[$stat]] = 1;
         }
         //排序
         $orderMap = ['1' => self::tableName() . '.create_time', '2' => IProductStat::tableName() . '.support_num', '3' => self::tableName() . '.update_time'];
         //默认排序
         $orderBy[self::tableName() . '.status'] = SORT_DESC;
         if (in_array($order, array_keys($orderMap))) {
             $orderBy[$orderMap[$order]] = SORT_DESC;
         } else {
             $orderBy[self::tableName() . '.id'] = SORT_DESC;
         }
         // print_r($conditions);exit;
         // echo "zhanglu";
         // print_r($orderBy);exit;
         //data
         $return = self::find()->joinWith(['stat', 'extra', 'aproduct' => function ($query) {
             return $query->with('apstat')->orderBy(['id' => SORT_DESC]);
         }])->andWhere(self::tableName() . '.status != :status', [':status' => 0])->andWhere([self::tableName() . '.uid' => $uid])->andWhere($conditions)->orderBy($orderBy)->asArray()->all();
     } else {
         $return = false;
     }
     // print_r($return);exit;
     return $return;
 }
コード例 #2
0
 /**
  * 定义与ProductStat的关联关系
  */
 public function getProductstat()
 {
     return $this->hasOne(ProductStat::className(), ['product_id' => 'product_id']);
 }
コード例 #3
0
 /**
  * 数据修复
  *
  * @param string $type 统计类型
  *  - support_num 支持人数
  *  - paied_num 支付数量
  *  - partake_num 参与人数
  *  - amount 总金额
  *  默认为空
  * @param string $method 统计方式
  *  - product 产品统计(默认)
  *  - activity 活动产品统计
  * @param string $ids 产品ID集合
  *  产品ID集合的格式为"产品ID1,产品ID2,.....产品IDN"
  */
 public function actionRepair($type = '', $method = 'product', $ids = '')
 {
     $page = 1;
     $perPage = 50;
     $startNum = ($page - 1) * $perPage;
     $result = [];
     $options = [];
     $count = 0;
     $mOrder = new Order();
     $types = ['support_num', 'paied_num', 'partake_num', 'amount'];
     $methods = ['product', 'activity'];
     $type = trim($type);
     $time = microtime(true);
     $log = new FileTarget();
     if (!$type) {
         die("Error: Param type is empty\n");
     }
     if (!in_array($type, $types)) {
         die("Error: Illegal Type\n");
     }
     if (!in_array($method, $methods)) {
         die("Error: Illegal Method\n");
     }
     if ($method == 'activity') {
         $ac = ActivityProductStat::find();
     } else {
         $ac = ProductStat::find();
     }
     $log->logFile = Yii::$app->getRuntimePath() . '/logs/' . self::LOGNAME_PREFIX . $method . '_' . $type . '_' . date('YmdHis') . '.log';
     if ($ids) {
         $ids = array_map('trim', explode(',', $ids));
         $ids = array_map('intval', $ids);
         $ids = array_filter($ids);
         $ids = array_unique($ids);
         $result = $ac->where(['product_id' => $ids])->all();
     } else {
         $result = $ac->offset($startNum)->limit($perPage)->all();
     }
     $this->_logger($log, 'Process Start');
     $this->_logger($log, 'Type:' . strtoupper($type));
     echo "Process Start\n";
     echo 'Type:' . strtoupper($type) . "\n";
     while ($result) {
         if ($result) {
             foreach ($result as $item) {
                 if (isset($item['product_id']) && $item['product_id']) {
                     $options['product_id'] = $item['product_id'];
                     if (isset($item['acti_id']) && $item['acti_id']) {
                         $options['acti_id'] = $item['acti_id'];
                     }
                     $count = $mOrder->getCountByType($type, $options);
                     if ($count === NULL || $count === false) {
                         continue;
                     }
                     $item[$type] = $count;
                     if ($item->save()) {
                         $this->_logger($log, 'Updated: pid=' . $item['product_id'] . ', count=' . $count);
                         echo 'Updated: pid=' . $item['product_id'] . ', count=' . $count . "\n";
                     } else {
                         $this->_logger($log, 'Error: pid=' . $item['product_id']);
                         echo 'Error: pid=' . $item['product_id'] . "\n";
                     }
                 }
             }
         }
         if ($ids) {
             break;
         } else {
             echo "========== Page {$page} finished processing ==========\n\n";
             $startNum = ($page - 1) * $perPage;
             $page++;
             $result = $ac->offset($startNum)->limit($perPage)->all();
         }
     }
     echo "Process Over\n";
     $this->_logger($log, 'Process Over');
     $log->export();
 }