public function actionAutomaticreceiving7() { set_time_limit(0); $model = new Order(); $list = $model->find()->where(['orderStatus' => 2])->all(); //查出所有已发货的订单 $res = []; foreach ($list as $k => $v) { $status = $v->orderExpressInfo->status; $updateTime = null; if (isset($v->orderExpressInfo->updateTime) && !empty($v->orderExpressInfo->updateTime)) { $updateTime = $v->orderExpressInfo->updateTime; } $updateTime = strtotime($updateTime); if ($updateTime && $status == 4) { $interval = strtotime(date('Y-m-d H:i:s', time())) - $updateTime; $day = $interval / 86400; //60s*60min*24h if ($day > 7) { array_push($res, ['id' => $v->id, 'orderStatus' => 3]); } } } $model->updateOrderStatusByBatch($res); //系统自动确认收货(批量) }
public function actionStats() { $memberId = $this->getQuery('memberId'); if (empty($memberId)) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $accountId = $this->getAccountId(); $memberOrderStats = StatsMemberOrder::getByConsumerId($accountId, $memberId); $order = Order::getLastByConsumerId($accountId, $memberId); if (empty($order)) { $result = ['lastOperateTime' => '', 'operateInterval' => null]; } else { $lastDate = MongodbUtil::MongoDate2String($order->operateTime, 'Y-m-d'); $result = ['lastOperateTime' => $lastDate, 'operateInterval' => abs((strtotime(date('Y-m-d')) - strtotime($lastDate)) / 86400)]; } if (empty($memberOrderStats)) { $result['consumptionAmount'] = $result['recentConsumption'] = $result['consumption'] = $result['memberMaxConsumption'] = 0; } else { $result['consumptionAmount'] = round($memberOrderStats->consumptionAmount); $result['recentConsumption'] = $memberOrderStats->recentTransactionCount; $result['consumption'] = round($memberOrderStats->consumptionAmount / $memberOrderStats->transactionCount); $result['memberMaxConsumption'] = round($memberOrderStats->maxConsumption); } $orderStats = StatsOrder::getLatestByAccount($accountId); if (empty($orderStats)) { $result['consumptionAmountAvg'] = $result['recentConsumptionAvg'] = $result['consumptionAvg'] = $result['maxConsumption'] = 0; } else { $result['consumptionAmountAvg'] = round($orderStats->consumptionAmount / $orderStats->consumerCount); $result['recentConsumptionAvg'] = round($orderStats->recentTransactionTotal / $orderStats->consumerCount); $result['consumptionAvg'] = round($orderStats->consumptionAmount / $orderStats->transactionCount); $result['maxConsumption'] = round($orderStats->maxConsumptionTotal / $orderStats->consumerCount); } return $result; }
public function perform() { $args = $this->args; if (empty($args['mainMember']) || empty($args['otherMemberIds'])) { ResqueUtil::log(['Merge member args error' => $args]); return; } $mainMember = unserialize($args['mainMember']); $otherMemberIds = unserialize($args['otherMemberIds']); //Get Name and phone $name = $phone = ''; foreach ($mainMember->properties as $mainProperty) { if ($mainProperty['name'] === Member::DEFAULT_PROPERTIES_NAME) { $name = $mainProperty['value']; } if ($mainProperty['name'] === Member::DEFAULT_PROPERTIES_MOBILE) { $phone = $mainProperty['value']; } } ScoreHistory::updateAll(['$set' => ['memberId' => $mainMember->_id]], ['memberId' => ['$in' => $otherMemberIds]]); MemberLogs::deleteAll(['memberId' => ['$in' => $otherMemberIds]]); CampaignLog::updateAll(['$set' => ['member.id' => $mainMember->_id, 'member.cardNumber' => $mainMember->cardNumber, 'member.name' => $name, 'member.phone' => $phone]], ['member.id' => ['$in' => $otherMemberIds]]); PromotionCode::updateAll(['$set' => ['usedBy.memberId' => $mainMember->_id, 'usedBy.memberNumber' => $mainMember->cardNumber]], ['usedBy.memberId' => ['$in' => $otherMemberIds]]); GoodsExchangeLog::updateAll(['$set' => ['memberId' => $mainMember->_id, 'memberName' => $name, 'telephone' => $phone]], ['memberId' => ['$in' => $otherMemberIds]]); $otherMemberStrIds = []; foreach ($otherMemberIds as $otherMemberId) { $otherMemberStrIds[] = (string) $otherMemberId; } Order::updateAll(['$set' => ['consumer.id' => (string) $mainMember->_id, 'consumer.name' => $name, 'consumer.phone' => $phone]], ['consumer.id' => ['$in' => $otherMemberStrIds]]); Qrcode::deleteAll(['type' => Qrcode::TYPE_MEMBER, 'associatedId' => ['$in' => $otherMemberIds]]); }
public function actionIndex($accountId) { if (empty($accountId)) { echo 'accountId is invaild' . PHP_EOL; exit; } $where['accountId'] = new \MongoId($accountId); // delete member info Member::getCollection()->remove($where); //delete MemberLogs MemberLogs::getCollection()->remove($where); //delete scoreHistory ScoreHistory::getCollection()->remove($where); //delete CampaignLog CampaignLog::getCollection()->remove($where); //delete GoodsExchangeLog GoodsExchangeLog::getCollection()->remove($where); //delete MemberStatistics MemberStatistics::getCollection()->remove($where); //delete ReMemberCampaign ReMemberCampaign::getCollection()->remove($where); //delete StatsCampaignProductCodeQuarterly StatsCampaignProductCodeQuarterly::getCollection()->remove($where); //delete StatsMemberCampaignLogDaily StatsMemberCampaignLogDaily::getCollection()->remove($where); //delete StatsMemberDaily StatsMemberDaily::getCollection()->remove($where); //delete StatsMemberGrowthMonthly StatsMemberGrowthMonthly::getCollection()->remove($where); //delete StatsMemberGrowthQuarterly StatsMemberGrowthQuarterly::getCollection()->remove($where); //delete StatsMemberMonthly StatsMemberMonthly::getCollection()->remove($where); //delete StatsMemberPropAvgTradeQuarterly StatsMemberPropAvgTradeQuarterly::getCollection()->remove($where); //delete StatsMemberPropMonthly StatsMemberPropMonthly::getCollection()->remove($where); //delete StatsMemberPropQuaterly StatsMemberPropQuaterly::getCollection()->remove($where); //delete StatsMemberPropTradeCodeAvgQuarterly StatsMemberPropTradeCodeAvgQuarterly::getCollection()->remove($where); //delete StatsMemberPropTradeCodeQuarterly StatsMemberPropTradeCodeQuarterly::getCollection()->remove($where); //delete StatsMemberPropTradeQuarterly StatsMemberPropTradeQuarterly::getCollection()->remove($where); //delete PromotionCodeAnalysis PromotionCodeAnalysis::getCollection()->remove($where); //delete order Order::getCollection()->remove($where); //delete stats member order StatsMemberOrder::getCollection()->remove($where); //delete stats order StatsOrder::getCollection()->remove($where); //delete MembershipDiscount MembershipDiscount::getCollection()->remove($where); //delete couponLog CouponLog::getCollection()->remove($where); echo 'delete data successful.' . PHP_EOL; }
/** * Update recent transaction count * @param MongoId $accountId */ private function updateMemberRecentTransactionCount($accountId) { $operatTimeFrom = new MongoDate(strtotime(date('Y-m-d') . ' -6 months')); $operatTimeTo = new MongoDate(strtotime(date('Y-m-d'))); $recentTransactionStats = Order::getMemberTransactionCount($accountId, $operatTimeFrom, $operatTimeTo); foreach ($recentTransactionStats as $recentTransactionStat) { ModelStatsMemberOrder::updateAll(['$set' => ['recentTransactionCount' => $recentTransactionStat['count']]], ['consumerId' => $recentTransactionStat['_id']]); } }
/** * 修改订单状态 */ public static function editState($state) { $model = Order::findOne($state['id']); if (!$model) { return false; } $model->setAttributes(['state' => $state['state'], 'edittime' => time()]); return $model->save(); }
public function actionSave() { $request = Yii::$app->request; $user = $request->post('user'); $cart = $request->post('cart'); $deliveryAddress = $request->post('deliveryAddress'); if ($user != null && $cart != null) { $order = new Order(); $order->userId = $user['id']; $order->mobile = $user['mobile']; $order->email = $user['email']; $order->cart = $cart; $order->balancePoints = $user['balancePoints']; $order->createDate = time(); if ($deliveryAddress == 0) { $order->gender = $user['gender']; $order->name = $user['name']; $order->city = $user['city']; $order->address = $user['address']; $order->zipCode = $user['zipCode']; } else { $order->gender = $user['gender_backup']; $order->name = $user['name_backup']; $order->city = $user['city_backup']; $order->address = $user['address_backup']; $order->zipCode = $user['zip_backup']; } if ($order->validate()) { $order->save(); return $order->_id; } else { $error = $order->errors; } } $code = 500; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['code' => $code]; }
public function getOrderProducts($model) { $order = Order::findOne($model->id); $result = '<ul>'; foreach ($order->orderItems as $item) { if ($item->product) { $result .= '<li><a href="/' . $item->product->slug_ru . '">' . $item->title . '. ' . $item->price . ' ' . $item->product->currency . ' (' . $item->quantity . ' шт.)' . '</a></li>'; } else { $result = '<li>Товар был удален.</li>'; } } $result .= '</ul>'; return $result; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status ? array_search(mb_convert_case(mb_strtolower($this->status), MB_CASE_TITLE), Order::getStatuses()) : $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_at_date' => $this->created_at_date, 'updated_at_date' => $this->updated_at_date]); $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'department', $this->department])->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['HANDPHONE' => $this->HANDPHONE, 'GRANDTOTAL' => $this->GRANDTOTAL, 'CREATE_DATED' => $this->CREATE_DATED]); $query->andFilterWhere(['like', 'G_ORDER', $this->G_ORDER])->andFilterWhere(['like', 'G_RANDOM', $this->G_RANDOM])->andFilterWhere(['like', 'G_PESAN', $this->G_PESAN])->andFilterWhere(['like', 'USER_ID', $this->USER_ID])->andFilterWhere(['like', 'USER_NAME', $this->USER_NAME])->andFilterWhere(['like', 'NAMA_CUSTOMER', $this->NAMA_CUSTOMER])->andFilterWhere(['like', 'ALAMAT_CUSTOMER', $this->ALAMAT_CUSTOMER])->andFilterWhere(['like', 'EMAIL_CUSTOMER', $this->EMAIL_CUSTOMER])->andFilterWhere(['like', 'STATUS', $this->STATUS]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { //$uid = Yii::$app->user->identity->id; $query = Order::find(); //->where(['id' => $uid])->all(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['user_id' => $this->user_id, 'product_id' => $this->product_id, 'id' => $this->id]); $query->andFilterWhere(['username' => $this->username])->andFilterWhere(['like', 'qty', $this->qty])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'Status', $this->Status]); return $dataProvider; }
public function updateOrderStatus($id, $orderStatus) { $model = Order::findOne($id); if (!$model) { return false; } //订单状态: 0-待付款 1-待发货 2-已发货 3-待评论 4-交易成功 5-已关闭 switch ($orderStatus) { case 0: //待付款 $model->orderStatus = 0; $model->onSaleTime = date('Y-m-d H:i:s', time()); break; case 1: //已经付款 等待发货 $model->orderStatus = 1; $model->orderPayTime = date('Y-m-d H:i:s', time()); break; case 2: //系统已经发货,等待快递反馈运单信息 $model->orderStatus = 2; break; case 3: //已经收货 等待评论 $model->orderStatus = 3; $model->isConfirm = 1; $model->confirmTime = date('Y-m-d H:i:s', time()); break; case 4: //已经评论,交易完成 $model->orderStatus = 4; break; case 5: //交易关闭(取消、订单等待支付时间过期等) $model->orderStatus = 5; break; } if ($model->save()) { return true; } return false; }
public static function badgeAllCount($modelName) { $count = 0; switch ($modelName) { case 'Order': $count = Order::find()->count(); break; case 'Call': $count = Call::find()->count(); break; case 'Review': $count = Review::find()->count(); break; default: $count = 0; break; } $options = ['class' => 'badge']; if ($count) { return Html::tag('span', $count, $options); } return Html::tag('span', $count, $options); }
public function actionUpdate($id) { $id = new \MongoId($id); $params = $this->getParams(); if (empty($params['status'])) { throw new BadRequestHttpException(Yii::t('store', 'status_missing')); } if (false === Order::checkOrderStatus($params['status'])) { throw new InvalidParameterException(Yii::t('store', 'status_invalid')); } $orderInfo = Order::findByPk($id); if (!empty($orderInfo) && $orderInfo->status == Order::ORDER_STATUS_WAITING) { $orderInfo->status = $params['status']; if (Order::ORDER_STATUS_FINISHED == $params['status']) { $orderInfo->payWay = self::ORDER_PAY_WAY; } $orderInfo->operateTime = new \MongoDate(); if ($orderInfo->save()) { return $orderInfo; } } throw new ServerErrorHttpException(Yii::t('common', 'update_fail')); }
public static function badges($modelName) { $count = 0; switch ($modelName) { case 'Order': $count = Order::find()->where(['status' => Order::STATUS_NEW])->count(); break; case 'Call': $count = Call::find()->where(['status' => Call::STATUS_NEW])->count(); break; case 'Review': $count = Review::find()->where(['status' => Review::STATUS_NEW])->count(); break; default: $count = 0; break; } $options = ['class' => 'label-danger label-as-badge']; if ($count) { return Html::tag('span', $count, $options); } $options = ['class' => 'label-info label-as-badge']; return Html::tag('span', $count, $options); }
public function actionOrder() { $order = new Order(); /* @var $cart ShoppingCart */ $cart = \Yii::$app->cart; /* @var $products Product[] */ $products = $cart->getPositions(); $total = $cart->getCost(); // echo var_dump($order->errors). "<br>"; // echo var_dump($order->validate()). "<br>"; // die('fdf'); if ($total === 0) { \Yii::$app->session->addFlash('info', 'У вас корзина пуста.'); } if ($order->load(\Yii::$app->request->post()) && $order->validate() && $total) { $transaction = $order->getDb()->beginTransaction(); $order->total_price = $total; $order->save(false); foreach ($products as $product) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->title = $product->title; $orderItem->price = $product->getPrice(); $orderItem->product_id = $product->id; $orderItem->quantity = $product->getQuantity(); if (!$orderItem->save(false)) { $transaction->rollBack(); \Yii::$app->session->addFlash('error', 'Не можете оформить заказ. Пожалуйста свяжитесь с нами.'); return $this->redirect('catalog/list'); } } $transaction->commit(); \Yii::$app->cart->removeAll(); $order->sendEmail('Новый Заказ', 'order'); \Yii::$app->session->addFlash('success', 'Спасибо за ваш заказ. Мы свяжемся с Вами в ближайшее время.'); return $this->goHome(); // return $this->redirect('catalog/list'); } return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $total]); }
/** * Finds the Order model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Order the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Order::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
$this->title = 'Заказы'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="order-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Order', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'first_name', 'last_name', 'city', 'phone', ['label' => 'Продукты', 'format' => 'raw', 'value' => function ($model) { return Order::getOrderProducts($model); }], ['attribute' => 'status', 'format' => 'raw', 'value' => function ($model) { return Order::getOrderStatesGoodly($model); }], ['attribute' => 'total_price', 'format' => 'raw', 'value' => function ($model) { return $model->total_price . ' грн.'; }], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public static function search($params, $accountId) { $query = Order::find(); $condition = self::createCondition($params, $accountId); $query->orderBy(self::normalizeOrderBy($params)); $query->where($condition); return new ActiveDataProvider(['query' => $query]); }
/** * @return \yii\db\ActiveQuery */ public function getOrder() { return $this->hasOne(Order::className(), ['id' => 'order_id']); }
$this->params['breadcrumbs'][] = ['label' => 'Orders', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="order-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'first_name', 'last_name', 'city', 'phone', 'department', 'note', ['attribute' => 'status', 'format' => 'raw', 'value' => Order::getOrderStatesGoodly($model)], 'created_at', 'updated_at', 'created_at_date', 'updated_at_date']]); ?> <article> <h2>Товар</h2> <?php echo Order::getOrderProducts($model); ?> </article> </div>
public function actionPdf($id) { /* $mpdf=new mPDF(); $mpdf->WriteHTML($this->renderPartial('mpdf',['model' => $this->findModel($id),])); //$mpdf->WriteHTML($this->renderPartial('mpdf')); $mpdf->Output('Expdf.pdf', 'D'); exit; */ // $model = new Order(); // $total = new Chart(); $sql = Order::find()->where(['G_ORDER' => $id])->asArray()->one(); $list = Chart::find()->where(['FAKTUR' => $id])->asArray()->all(); $total = Chart::find()->select('sum(HARGA) as total')->where(['FAKTUR' => $id])->asArray()->all(); $mpdf = new mPDF(); $mpdf->WriteHTML($this->renderPartial('invoice', ['sql' => $sql, 'list' => $list, 'total' => $total])); $mpdf->Output(); exit; //return $this->renderPartial('mpdf'); }
</head> <body> <div class="order-index"> <br> <br> <br> <br> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <br> <div class="container wrapme"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'username', 'filter' => Order::getUsername()], ['label' => 'Product Name', 'attribute' => 'product_id', 'value' => 'product.name', 'filter' => Order::getProductName()], ['label' => 'Quantity', 'attribute' => 'qty'], ['label' => 'Order ID', 'attribute' => 'id'], 'date', 'Status', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div> </div> <script src="assets/js/jquery-2.1.3.min.js"></script> <script src="assets/js/bootstrap.min.js"></script> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> <script src="assets/js/jquery.actual.min.js"></script> <script src="assets/js/smooth-scroll.js"></script> <script src="assets/js/owl.carousel.js"></script> <script src="assets/js/script.js"></script> </div> </body> </html>
private function _getOrder($orderId) { if ($orderId != null) { $order = Order::findOne($orderId); if ($order != null) { return $order; } else { return null; } } else { return null; } }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasMany(Order::className(), ['promotion_id' => 'id']); }