コード例 #1
0
ファイル: Goods.php プロジェクト: timelessmemory/uhkklp
 /**
  * create goods
  * @param $result array
  * @param $accountId objectId
  */
 public static function createGoods($result, $accountId)
 {
     $goodsData = [];
     //get max order
     $where = ['accountId' => $accountId, 'isDeleted' => \backend\components\BaseModel::NOT_DELETED];
     $goods = Goods::find()->where($where)->orderBy(['order' => SORT_DESC])->one();
     if (empty($goods)) {
         $order = 1;
     } else {
         $order = $goods['order'] + 1;
     }
     foreach ($result as $key => $info) {
         $data = [];
         $data['productId'] = new MongoId($info['productId']);
         $data['productName'] = $info['productName'];
         $data['sku'] = $info['sku'];
         $data['categoryId'] = !empty($info['categoryId']) ? new \MongoId($info['categoryId']) : '';
         $data['score'] = intval($info['score']);
         $data['total'] = empty($info['total']) ? '' : new \MongoInt32($info['total']);
         $data['accountId'] = $accountId;
         $data['order'] = $order;
         $data['pictures'] = empty($info['pictures']) ? [] : $info['pictures'];
         $data['status'] = Goods::STATUS_OFF;
         $data['usedCount'] = 0;
         $data['offShelfTime'] = new \Mongodate();
         $order++;
         $goodsData[] = $data;
     }
     if (count($goodsData) > 0) {
         Goods::batchInsert($goodsData);
     }
     return ['status' => 'OK', 'message' => 'create successful'];
 }