Exemplo n.º 1
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $id = intval($this->getDataItem('id', 0));
     $state = $this->getDataItem('state', null);
     if ($id <= 0 || empty($state)) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR);
     }
     $stateValues = ['cancel', 'delete'];
     if (!in_array($state, $stateValues)) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '状态值错误.');
     }
     $stateValue = 0;
     switch ($state) {
         case $stateValues[0]:
             $stateValue = OrderState::Cancel;
             break;
         case $stateValues[1]:
             $stateValue = OrderState::Delete;
             break;
     }
     UserOrder::SetOrderState($this->getUserAuth()->userId, $id, $stateValue);
     $this->setResult(['success' => 1]);
 }
Exemplo n.º 2
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $mobile = $this->getDataItem('mobile');
     $payType = $this->getDataItem('pay_type');
     $goods = $this->getDataItem('goods');
     if (empty($mobile) || empty($payType) || empty($goods) || !is_array($goods) || count($goods) == 0) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR);
     }
     $payTypeValue = $this->getPayTypeNum($payType);
     if ($payTypeValue <= 0) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '支付方式不支持.');
     }
     $userId = $this->getUserAuth()->userId;
     $goodsInfo = $this->getGoodsInfo($goods);
     if (count($goodsInfo) == 0) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '商品内容为空.');
     }
     // 计算总价格
     $money = 0;
     foreach ($goodsInfo as $gi) {
         $money = $money + $gi['order_number'] * $gi['service_price'];
     }
     $longId = Util::LongId(true);
     $orderId = $this->addOrderBase($longId, $mobile, $payTypeValue, $money, $userId);
     if ($orderId == 0) {
         return;
     }
     foreach ($goodsInfo as $gi) {
         $ogid = $this->addOrderGoods($userId, $orderId, $gi);
         if ($ogid <= 0) {
             UserOrder::SetOrderState($userId, $orderId, -1);
             return;
         }
     }
     $weixinPay = null;
     // 判断是否微信支付,微信支付需去下单
     if ($payTypeValue == 1) {
         $pay = new Pay();
         $weixinPay = $pay->weiXin2AppPay($orderId);
     }
     $this->setResult(['success' => 1, 'order_id' => $orderId, 'order_long_id' => $longId, 'weixin_pay' => $weixinPay ? $weixinPay : null]);
 }