コード例 #1
0
ファイル: User_Model.php プロジェクト: GavinLai/SimMatch
 static function saveFeedback($data)
 {
     $user_id = $GLOBALS['user']->ec_user_id;
     if ($user_id) {
         //对于登录用户,获取用户信息
         $uinfo = D()->from(ectable('users'))->where(['user_id' => $user_id])->select('user_id,email,user_name,nick_name')->get_one();
         if (!empty($uinfo)) {
             $uinfo_append = ['user_id' => $uinfo['user_id'], 'user_name' => $uinfo['user_name'], 'nick_name' => $uinfo['nick_name']];
             if ('' == $data['user_email'] && '' != $uinfo['email']) {
                 $data['user_email'] = $uinfo['email'];
             }
             $data = array_merge($data, $uinfo_append);
         }
     }
     $fid = D()->insert(ectable('feedback'), $data, true, true);
     return $fid;
 }
コード例 #2
0
ファイル: class.Goods.php プロジェクト: GavinLai/SimMatch
 /**
  * 搜索产品库,先搜索产品分类,如果为空则搜索品牌,如果再为空就搜索产品名称
  * 
  * @param string  $keyword
  * @param integer $limit
  * @return array
  */
 static function search($keyword, $limit = 10)
 {
     $result_final = [];
     $keyword = strtolower($keyword);
     // 先搜索分类名称
     $cat_ids = D()->from(ectable('category'))->where("`is_show`=1 AND LOWER(`cat_name`) like '%%%s%%'", $keyword)->select("`cat_id`")->fetch_column('cat_id');
     $all_cat_ids = [];
     if (!empty($cat_ids)) {
         foreach ($cat_ids as $id) {
             $all_cat_ids = array_merge($all_cat_ids, [$id], self::getChildCategoryIds($id));
         }
     }
     $result_cat = [];
     if (!empty($all_cat_ids)) {
         $all_cat_ids = array_unique($all_cat_ids);
         $result_cat = D()->from(ectable('goods'))->where("`cat_id` IN(%s)", implode(',', $all_cat_ids))->order_by("`add_time` DESC")->limit($limit)->select()->fetch_array_all();
     }
     if (empty($result_cat)) {
         //搜索分类产品结果为空,则继续搜索品牌
         $brand_ids = D()->from(ectable('brand'))->where("`is_show`=1 AND LOWER(`brand_name`) like '%%%s%%'", $keyword)->select("`brand_id`")->fetch_column('brand_id');
         $result_brand = [];
         if (!empty($brand_ids)) {
             $result_brand = D()->from(ectable('goods'))->where("`brand_id` IN(%s)", implode(',', $brand_ids))->order_by("`add_time` DESC")->limit($limit)->select()->fetch_array_all();
         }
         if (empty($result_brand)) {
             //搜索品牌下的产品结果也为空,则继续搜索产品名称
             $result_final = D()->from(ectable('goods'))->where("`goods_name` like '%%%s%%'", $keyword)->order_by("`add_time` DESC")->limit($limit)->select()->fetch_array_all();
         } else {
             $result_final = $result_brand;
         }
     } else {
         $result_final = $result_cat;
     }
     return $result_final;
 }
コード例 #3
0
 /**
  * action 'notify'
  * 微信支付统一下订单回调
  *
  * @param Request $request
  * @param Response $response
  */
 public function notify(Request $request, Response $response)
 {
     Wxpay::nofify(function ($data, &$msg) {
         //trace_debug('api_wxpay_notify_data', $data);
         //trace_debug('api_wxpay_notify_msg', $msg);
         if ('OK' == $msg) {
             // 成功合法的订单
             // 关注的数据
             $openid = $data['openid'];
             //用户openid
             $is_subscribe = $data['is_subscribe'];
             //是否关注公众账号:'Y' or 'N'
             $total_fee = $data['total_fee'];
             //订单总金额,单位为分
             $bank_type = $data['bank_type'];
             //付款银行
             $transaction_id = $data['transaction_id'];
             //微信支付订单号
             $order_sn = $data['out_trade_no'];
             //自身订单号
             $attach = isset($data['attach']) ? $data['attach'] : '';
             //商家自定义数据,原样返回
             $time_end = $data['time_end'];
             //支付完成时间,格式为yyyyMMddHHmmss,如:20141030133525
             $time_end = Fn::to_timestamp($time_end);
             //对日志表"写锁定",避免其他线程进入干扰(这时其他线程对表pay_log的读写都要等待)
             $ec_paylog = ectable('pay_log');
             D()->lock_tables($ec_paylog, DB::LOCK_WRITE, '', TRUE);
             //检查支付日志表,以确定订单是否存在(之所以用日志表而不是主表order_info,是为了在锁表期间不阻塞到前台访问频繁的主表)
             $pay_log = D()->from($ec_paylog, DB::WRITABLE)->where(['order_sn' => $order_sn])->select()->get_one();
             if (empty($pay_log)) {
                 $msg = '订单号不存在';
                 D()->unlock_tables();
                 // 解锁
                 return false;
             }
             $order_id = $pay_log['order_id'];
             //检查支付金额是否正确
             if (intval($pay_log['order_amount'] * 100) != $total_fee) {
                 $msg = '金额不对';
                 D()->unlock_tables();
                 // 解锁
                 return false;
             }
             //检查订单状态
             if (!$pay_log['is_paid']) {
                 //未付款
                 //更新pay_log
                 D()->update($ec_paylog, ['is_paid' => 1], ['order_id' => $order_id], true);
                 // 更新完立马解锁
                 D()->unlock_tables();
                 //立马修改订单状态为已付款
                 $updata = ['pay_trade_no' => $transaction_id, 'order_status' => OS_CONFIRMED, 'confirm_time' => simphp_gmtime(), 'pay_status' => PS_PAYED, 'pay_time' => simphp_gmtime($time_end), 'money_paid' => $pay_log['order_amount'], 'order_amount' => 0, 'pay_data2' => json_encode($data)];
                 D()->update(ectable('order_info'), $updata, ['order_id' => $order_id], true);
                 //记录订单操作记录
                 Order::order_action_log($order_id, ['action_note' => '用户支付']);
                 //更新订单下所有商品的"订单数"
                 Goods::updateGoodsOrderCntByOrderid($order_id);
             } else {
                 D()->unlock_tables();
                 // 解锁
             }
             return true;
         }
         return false;
     });
 }
コード例 #4
0
ファイル: class.Order.php プロジェクト: GavinLai/SimMatch
 /**
  * 
  * @param integer $order_id
  * @return array
  */
 static function info($order_id)
 {
     if (empty($order_id)) {
         return false;
     }
     $order_id = intval($order_id);
     $row = D()->from(ectable('order_info'))->where(['order_id' => $order_id])->select()->get_one();
     return $row;
 }
コード例 #5
0
ファイル: class.Member.php プロジェクト: GavinLai/SimMatch
 /**
  * 获取ecshop数据表的region id
  * @param string $city
  * @param string $province
  * @param string $country
  * @return number
  */
 public static function getECRegionId($city, $province = '', $country = '')
 {
     $theid = 0;
     if (!empty($city)) {
         $ectb = ectable('region');
         $sql = "SELECT `region_id` FROM {$ectb} WHERE `region_name`='%s' AND ";
         $row = D()->raw_query($sql . "`region_type`=2", $city)->get_one();
         if (empty($row)) {
             $row = D()->raw_query($sql . "`region_type`=1", $province)->get_one();
             if (empty($row)) {
                 $row = D()->raw_query($sql . "`region_type`=0", $country)->get_one();
                 if (!empty($row)) {
                     $theid = $row['region_id'];
                 }
             } else {
                 $theid = $row['region_id'];
             }
         } else {
             $theid = $row['region_id'];
         }
     }
     return $theid;
 }