Exemple #1
0
 /**
  * update record
  *
  * @param App_Shop_Dm $dm
  * @return multitype:|Ambigous <boolean, number, rowCount>
  */
 public function update($id, App_Shop_Dm $dm)
 {
     if (true !== ($r = $dm->beforeUpdate())) {
         return $r;
     }
     return $this->loadDao()->update($id, $dm->getData());
 }
Exemple #2
0
 public function makeOrder($userid, $schoolId, $merchandisesInfo, $to, $phone, $address, $note, $source, $orderExpressTime = '', $orderHour = '', $orderMinutes = '', $shopDeduct = array())
 {
     //get ordered merchandise and information relates to it
     //say. 数量,积分
     //基于商店拆分订单
     $groupOrdersByShop = array();
     $orderItems = $merchandisesInfo;
     foreach ($orderItems as $key => &$eachItem) {
         $eachItem = (array) $eachItem;
         $groupOrdersByShop[$eachItem['shopid']][] = $eachItem;
     }
     $orderTime = $orderHour . ':' . $orderMinutes;
     $deliveryInfo = array("to" => $to, "phone" => $phone, "address" => $address, "note" => $note, "preorder" => $orderExpressTime == '', "preoderat" => $orderTime);
     $notes = array();
     if (is_array($note)) {
         foreach ($note as $key => $value) {
             $notes[$value['shopid']] = $value['note'];
         }
     }
     $generatedOrderIds = array();
     $totalDianMoney = 0;
     $isFirst = $this->isFirstOrder($userid);
     $isFirstSince0331 = $isFirst || $this->isFirstOrder($userid, '2014-03-31');
     foreach ($groupOrdersByShop as $shopid => $orderItems) {
         $shopInfo = $this->_getShopDS()->getByShopId($shopid);
         //generateOrderNumber
         $generatedOrderNumber = $this->generateOrderNumber();
         //$successMessage = "下单成功";
         $totalMoney = 0;
         $totalOriginalMoney = 0;
         //estimate delivery time(from order to user)
         $estimatetime = $this->_getShopDS()->getShopOrderTimeBase($shopid);
         date_default_timezone_set("Asia/Shanghai");
         $currentTime = time() + $estimatetime * 60;
         $estimateDeliveryat = date('Y-m-d H:i:s', $currentTime);
         if (is_array($note)) {
             $mark = $notes[$shopid];
         } else {
             $mark = $note;
         }
         //check shop if is order to user(代课下单的意思)
         $ifordertouser = $shopInfo['openordertouser'];
         //$this->_getShopDS()->checkIfOrderToUser($shopid);
         //check order items
         //compose order data
         Wind::import('EXT:4tschool.service.myorder.dm.App_Order_Dm');
         $dmorder = new App_Order_Dm();
         $dmorder->setUserId($userid)->setSchoolId($schoolId)->setShopId($shopid)->setOrderNumber($generatedOrderNumber)->setStatus(0)->setPaymethod(1)->setDelivermethod()->setTo($deliveryInfo['address'])->setToWho($deliveryInfo['to'])->setToMobile($deliveryInfo['phone'])->setPreOrder($deliveryInfo['preorder'])->setPreOrderAt($deliveryInfo['preorderat'])->setSavingtotal($totalOriginalMoney - $totalMoney)->setOrdermoney($totalMoney)->setNote($mark)->setEstimatedeliveryat($estimateDeliveryat)->setEstimatetime($estimatetime)->setSource($source)->setFirstOrder($isFirst ? 1 : 0)->setFirstOrderSince0331($isFirstSince0331)->setOrderToUser($ifordertouser ? 1 : 0);
         $orderid = $this->insertOrder($dmorder);
         //calculate deduct price
         $totalDeduct = 0;
         if ($orderid > 0) {
             $generatedOrderIds[] = $orderid;
             //insert order status history
             $this->insertOrderStatusHistory($orderid, $this->loginUser->uid, 0, 1);
             //order sequence
             $sequence = $this->getOrderSequence($orderid);
             $i = 0;
             $totalQuantity = 0;
             foreach ($orderItems as $key => $value) {
                 $i++;
                 $merchandiseId = $value['merchandiseId'];
                 //check item
                 $merchandiseInfo = $this->_getMerchandiseDS()->getMerchandiseById($merchandiseId);
                 $needPackingPrice = $merchandiseInfo['needPackingPrice'];
                 if ($needPackingPrice == 1) {
                     $packingPrice = $shopInfo['packingprice'] + $shopInfo['deliveryprice'];
                 } else {
                     $packingPrice = 0.0;
                 }
                 $totalMoney = $totalMoney + ($merchandiseInfo['currentprice'] + $packingPrice) * $value['qty'];
                 $totalOriginalMoney = $totalOriginalMoney + ($merchandiseInfo['price'] + $packingPrice) * $value['qty'];
                 //更新商店人气
                 Wind::import('EXT:4tschool.service.shop.dm.App_Shop_Dm');
                 $shopDM = new App_Shop_Dm();
                 $shopDM->setOrderCount($shopInfo['ordercount'] + $value['qty']);
                 $this->_getShopDS()->update($shopInfo['id'], $shopDM);
                 $MDeductMoney = array();
                 $usedPromo = '';
                 //check M deducted price
                 foreach ($promos['Match'] as $key => $eachPromo) {
                     if ($eachPromo['MID'] == $merchandiseId) {
                         $MDeductMoney[$merchandiseId] = $eachPromo['Deduct'];
                         $usedPromo = $eachPromo['ShopName'] . "限时活动, 满" . $eachPromo['Meet'] . "元," . $eachPromo['MerchandiseName'] . "立减" . $eachPromo['Deduct'] . "元";
                         break;
                     }
                 }
                 $priceIncludingPacking = $merchandiseInfo['currentprice'] + $packingPrice;
                 $MTotalMoney = $priceIncludingPacking * $value['qty'] - $MDeductMoney[$merchandiseId];
                 Wind::import('EXT:4tschool.service.myorder.dm.App_OrderItem_Dm');
                 $dmitem = new App_OrderItem_Dm();
                 $dmitem->setOrderId($orderid)->setMerchandiseId($merchandiseId)->setSchoolAreaId($shopInfo['areaid'])->setQuatity($value['qty'])->setPriceOriginal($merchandiseInfo['price'])->setPriceOfferDescription("优惠了" . ($merchandiseInfo['price'] - $merchandiseInfo['currentprice']) * $value['qty'] . "元")->setPrice($priceIncludingPacking)->setSaving(($merchandiseInfo['price'] - $merchandiseInfo['currentprice']) * $value['qty'])->setIntegral($MTotalMoney)->setSequence($sequence . "-" . $i)->setPackingprice($packingPrice)->setStatus(0)->setTotalMoney($MTotalMoney)->setPromoUsed($usedPromo);
                 $generatedItemId = $this->insertOrderItem($dmitem);
                 //update merchandise order count
                 $this->_getMerchandiseDS()->orderCountIncrease($merchandiseId);
             }
             //calculate 点币
             $dianMoney = 0;
             $ordermoney = $totalMoney - $totalDeduct;
             //check if shop has 返利
             $hasShopProfit = $shopInfo['ifrebate'];
             $rate = $shopInfo['rebatefromshop'];
             if ($hasShopProfit == 1) {
                 $rmbShopReturn = $ordermoney * $rate;
                 $rmbforUser = $this->_getShopDailySaleDs()->getUserProfit($rmbShopReturn);
                 $dianMoney = $rmbforUser * 10;
             } else {
                 $rmbShopReturn = 0;
                 $rate = 0;
             }
             Wind::import('EXT:4tschool.service.myorder.dm.App_Order_Dm');
             $dmUpdateOrder = new App_Order_Dm();
             $dmUpdateOrder->setSavingtotal($totalOriginalMoney - $totalMoney + $totalDeduct)->setOrdermoney($totalMoney - $totalDeduct)->setDeservedPointcoin($dianMoney)->setShopreturn($rmbShopReturn)->setRebatefromshop($rate);
             //更新订单总金额
             $this->updateOrder($orderid, $dmUpdateOrder);
             //notify user
             $this->_getOrderStatusNotifyDs()->SendStatusNotify(0, $orderid);
             //notify user
         }
         //push message to shop client, notify that there is new order
         $notifytitle = $totalMoney . "元新订单等待您接收-点餐哟";
         $notifycontent = "请开启订单接收软件进行接单, 谢谢";
         //notify shop
         $this->_getOrderStatusNotifyDs()->PushToShopClient($shopid, $shopInfo['openordertouser'], $notifytitle, $notifycontent);
     }
     return $generatedOrderIds;
 }
Exemple #3
0
 public function saveUrl($shopId, $url)
 {
     $dm = new App_Shop_Dm();
     $dm->setImageUrl($url)->setLastUpdateTime(Pw::getTime());
     $result = $this->_getShopDs()->update($shopId, $dm);
     return $result;
 }