public function run()
 {
     $faker = Faker::create();
     $order_types = ['shipping', 'delivery', 'pick-up'];
     $order_statuses = ['okay', 'not okay', 'maybe'];
     foreach (range(1, 10) as $index) {
         ProductOrder::create(['product_id' => $faker->numberBetween($min = 1, $max = 10), 'customer_id' => $faker->numberBetween($min = 1, $max = 10), 'product_order_date_id' => $faker->numberBetween($min = 1, $max = 10), 'order_type' => $order_types[array_rand($order_types)], 'order_status' => $order_statuses[array_rand($order_statuses)]]);
     }
 }
    public static function getLoadSql()
    {
        $tableName = ProductOrder::getTableName();
        return '
			SELECT
				`' . $tableName . '`.*
			FROM
				`' . ProductOrder::getDbName() . '`.`' . $tableName . '`
		';
    }
 public function setUp()
 {
     parent::setUp();
 }
 public static function setConnection(mysqli $newConnection)
 {
     self::$db = $newConnection;
 }
 /**
  * Resource destory action
  * DELETE      /resource/{id}
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $data = $this->model->find($id);
     if (is_null($data)) {
         return Redirect::back()->with('error', '没有找到对应的' . $this->resourceName . '。');
     } elseif ($data) {
         $trading = ProductOrder::where('product_id', $id)->where('is_payment', true)->where('is_checkout', false)->first();
         if ($trading) {
             return Redirect::back()->with('warning', $this->resourceName . '正在交易中,暂时不能删除。');
         } else {
             $model = $this->model->find($id);
             $thumbnails = $model->thumbnails;
             if ($thumbnails != NULL) {
                 destoryUploadImages($this->thumbnailsPath, $thumbnails);
                 $images = ProductPictures::where('product_id', $id)->get();
                 foreach ($images as $singleImage) {
                     destoryUploadImages($this->destinationPath, $singleImage->filename);
                 }
             }
             $timeline = Timeline::where('slug', $model->slug)->where('user_id', Auth::user()->id)->first();
             $timeline->delete();
             $data->delete();
             return Redirect::back()->with('success', $this->resourceName . '删除成功。');
         }
     } else {
         return Redirect::back()->with('warning', $this->resourceName . '删除失败。');
     }
 }
 /**
  * Action: Aplipay trade notify
  * @return Response
  */
 public function tradeNotify()
 {
     require_once app_path('api/alipay/alipay.config.php');
     require_once app_path('api/alipay/lib/alipay_notify.class.php');
     // Get verification result
     $alipayNotify = new AlipayNotify($alipay_config);
     $verify_result = $alipayNotify->verifyNotify();
     if ($verify_result) {
         $out_trade_no = $_POST['out_trade_no'];
         // Order ID
         $trade_no = $_POST['trade_no'];
         // Alipay order ID
         $trade_status = $_POST['trade_status'];
         // Alipay trade status
         $product_order = ProductOrder::where('order_id', $out_trade_no)->first();
         $product_order->is_payment = true;
         $product_order->alipay_trade = $trade_no;
         $product_order->save();
         $product = Product::where('id', $product_order->product_id)->first();
         $product->quantity = $product->quantity - $product_order->quantity;
         $product->save();
         if ($_POST['trade_status'] == 'WAIT_BUYER_PAY') {
             echo "success";
         } else {
             if ($_POST['trade_status'] == 'WAIT_SELLER_SEND_GOODS') {
                 echo "success";
             } else {
                 if ($_POST['trade_status'] == 'WAIT_BUYER_CONFIRM_GOODS') {
                     echo "success";
                 } else {
                     if ($_POST['trade_status'] == 'TRADE_FINISHED') {
                         echo "success";
                     } else {
                         echo "success";
                     }
                 }
             }
         }
     } else {
         // Verification fail
         return Redirect::route('home');
     }
 }
 public function addProductOrder(ProductOrder $object)
 {
     $object->setCustomerId($this->getId());
     $object->setCustomer_Object($this);
     $this->getProductOrder_Collection()->add($object);
     return $object;
 }
 function adminsetselectedorderAction()
 {
     $type = $this->_request->getParam('type');
     if ($type == 'orderState') {
         $idStr = $this->_request->getParam('orderids');
         $idStrArray = explode(',', $idStr);
         $productOrderModel = new ProductOrder();
         foreach ($idStrArray as $idAndState) {
             if (null == $idAndState || '' == $idAndState) {
                 continue;
             }
             $idAndStateArray = explode('@', $idAndState);
             $productOrder = $productOrderModel->fetchRow('id = ' . $idAndStateArray[0]);
             // consumer cancel order
             if ($productOrder->state == 'CANCEL') {
                 continue;
             }
             // confirm used point in table 'reward_point_transaction_record'
             $rewardPointTransactionRecordModel = new RewardPointTransactionRecord();
             $rewardPointTransactionRecord = $rewardPointTransactionRecordModel->fetchRow('id = ' . $productOrder->reward_point_transaction_record_id);
             if ($rewardPointTransactionRecord == null) {
                 continue;
             } else {
                 $productModel = new Product();
                 $product = $productModel->fetchRow('id = ' . $productOrder->product_id);
                 if ($product == null) {
                     continue;
                 } else {
                     if ($idAndStateArray[1] == 'UNAPPROVED') {
                         $rewardPointTransactionRecord->point_amount = 0;
                     }
                 }
                 $rewardPointTransactionRecord->save();
             }
             // change order state
             $currenttime = date("Y-m-d H:i:s");
             $productOrder->state = $idAndStateArray[1];
             $productOrder->handle_date = $currenttime;
             $productOrder->save();
         }
     }
     $this->_helper->json('Success');
 }
Exemple #9
0
<div class="page_content" style="-webkit-transform: translate3d(0px, 0px, 0px);">
    <?php 
$this->renderPartial('//wechat/common/usertop');
?>
    <div class="col-lg-12" style="padding:10px 25px 0px 25px;min-height:350px;">
        <table class="table table-striped table-hover text-left" style="background-color:#f0f0f0;">
            <tr>
                <th>商品图片</th>
                <th>商品名称</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            <?php 
#获得用户资金记录
$accountlog = ProductOrder::model()->findAll("user_id=:user_id order by order_id desc limit 10", array(":user_id" => Yii::app()->user->getId()));
if ($accountlog) {
    foreach ($accountlog as $values) {
        ?>
                    <tr>
                        <td><?php 
        echo $values->product->product_s_img;
        ?>
</td>
                        <td><?php 
        echo $values->product->product_name;
        ?>
</td>
                        <td><?php 
        echo $values->order_status;
        ?>
</td>
 function ajaxchangeorderstateAction()
 {
     $this->_helper->layout->disableLayout();
     $uid = $this->_request->getParam('uid');
     $postData = $this->_request->getPost();
     $productOrderModel = new ProductOrder();
     $productOrderModel->update(array('state' => $postData['state']), 'id = ' . $uid);
     $this->_helper->json("Success");
 }
 function redeemAction()
 {
     $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->translate("GIFT_REDEEM");
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         $cartNamespace = new Zend_Session_Namespace('Cart');
         if ($cartNamespace->list == null) {
             $this->_redirect('gift/list');
             return;
         }
         // validate consumer info
         $consumerModel = new Consumer();
         $consumer = $consumerModel->fetchRow("email = '" . $this->_currentUser->email . "' and password = MD5('" . $formData['password'] . "')");
         if ($consumer == null) {
             $this->_flashMessenger->addMessage($this->view->translate("Gift_consumer_info_incorrect"));
             $this->_flashMessenger->addMessage(true);
             $this->_redirect('gift/confirmcart');
             return;
         }
         // check redeem condition
         $db = Zend_Registry::get('db');
         $selectTotalCompletedCampaign = $db->select();
         $selectTotalCompletedCampaign->from('campaign_participation', 'count(*)')->join('campaign_invitation', 'campaign_participation.campaign_invitation_id = campaign_invitation.id', null)->where('campaign_invitation.consumer_id = ?', $this->_currentUser->id);
         $this->view->completedCampaignAmount = $db->fetchOne($selectTotalCompletedCampaign);
         //			$selectTotalSubmittedReport = $db->select();
         //			$selectTotalSubmittedReport->from('report', 'count(*)')
         //			->where('state = "APPROVED"')
         //			->where('consumer_id = ?', $this->_currentUser->id);
         //			$this->view->submittedReportAmount = $db->fetchOne($selectTotalSubmittedReport);
         if ($this->view->completedCampaignAmount < 1 || $this->_currentUser->pest != null && $this->_currentUser->pest == 1) {
             $this->_flashMessenger->addMessage($this->view->translate("Gift_can_not_redeem_gift"));
             $this->_flashMessenger->addMessage(true);
             $this->_redirect('gift/confirmcart');
             return;
         }
         // check the point
         $selectUsablePoints = $db->select();
         $selectUsablePoints->from('reward_point_transaction_record', 'SUM(point_amount)')->where("consumer_id = ?", $this->_currentUser->id);
         $usablePoints = (int) $db->fetchOne($selectUsablePoints);
         $amountSelectedProductPoint = 0;
         foreach ($cartNamespace->list as $product) {
             $selectSelectedProductPoint = $db->select();
             $selectSelectedProductPoint->from('product', 'point')->where("id = " . $product['id']);
             $selectedProductPoint = (int) $db->fetchOne($selectSelectedProductPoint);
             $amountSelectedProductPoint += $product['amount'] * $selectedProductPoint;
         }
         if ($amountSelectedProductPoint > $usablePoints) {
             $this->_flashMessenger->addMessage($this->view->translate("Gift_have_no_enough_point"));
             $this->_flashMessenger->addMessage(true);
             $this->_redirect('gift/confirmcart');
             return;
         }
         // save shipping info
         $consumerModel = new Consumer();
         $id = $this->_currentUser->id;
         $consumer = $consumerModel->find($id)->current();
         $consumer->recipients_name = $formData['recipients_name'];
         $consumer->phone = $formData['phone'];
         $consumer->address1 = $formData['address1'];
         $consumer->postalcode = $formData['postalcode'];
         if ($formData['city'] != null && $formData['province'] != null) {
             $consumer->city = $formData['city'];
             $consumer->province = $formData['province'];
         }
         if ($formData['englishcity'] != null) {
             $consumer->city = $formData['englishcity'];
             $consumer->province = null;
         }
         if ($formData['province'] == '' && $formData['englishcity'] == null) {
             $consumer->city = null;
             $consumer->province = null;
         }
         $consumer->save();
         // save exchange records
         $currentTime = date("Y-m-d H:i:s");
         $rewardPointTransactionRecordModel = new RewardPointTransactionRecord();
         $prodcutOrderModel = new ProductOrder();
         $notificationModel = new Notification();
         $total_redeem_point = 0;
         foreach ($cartNamespace->list as $product) {
             // add records to reward_point_transaction_record table
             $rewardPointTransactionRecord = array("consumer_id" => $this->_currentUser->id, "DATE" => $currentTime, "transaction_id" => '4', "point_amount" => -$product['amount'] * $product['point']);
             $transactionRecordId = $rewardPointTransactionRecordModel->insert($rewardPointTransactionRecord);
             // add records to product_order table
             $prodcutOrder = array('consumer_id' => $this->_currentUser->id, 'product_id' => $product['id'], 'create_date' => $currentTime, 'state' => 'NEW', 'reward_point_transaction_record_id' => $transactionRecordId, 'amount' => $product['amount']);
             $prodcutOrderId = $prodcutOrderModel->insert($prodcutOrder);
             // roll back if an exception occurred
             // ...
             $total_redeem_point += $product['amount'] * $product['point'];
         }
         // add notification
         $notificationModel->createRecord("REDEEM_POINT", $this->_currentUser->id, $total_redeem_point);
         $this->paidGifts = $cartNamespace->list;
         $cartNamespace->list = null;
         // show redeem.phtml with "... Successfully"
         $this->_flashMessenger->addMessage("Gift_submit_orders_successfully");
         $this->_flashMessenger->addMessage(false);
         $this->_flashMessenger->addMessage($this->paidGifts);
         $this->_redirect('gift/thankyou');
     } else {
         $this->_redirect('gift/list');
     }
 }