# 开发指导
商城培训内容
一、目录结构(MVC模式)
(1)视图(View)
存放在views文件夹下,主要存放显示页面的php文件
(2)模型(Model)
存放在models文件夹下,存放对数据库表的操作方法
(3)控制(Controller)
存放在controllers文件夹下,存放控制方法。从用户接受请求,讲模型与视图匹配在一起,共同完成用户的请求。
(4)其他文件
config文件夹:存放商城的备置文件。例如数据库文件(db.ini.php),备置文件(config.ini.php)等。
api文件夹:存放接口文件。例如快递接口文件(logistic.php)。
static文件夹:存放css文件,js文件,图片。
task文件夹:存放计划任务文件。
二、查找文件
例子:根据 `http://shop.yuanfeng.com/index.php?ctl=Buyer_Cart&met=cart` 地址查找文件
`index.php` 是入口文件。
`ctl=Buyer_Cart` 控制器文件路径 `shop/controllers/Buyer/CartCtl.php`
`met=cart` 是 `CartCtl.php` 中的`cart`方法。
```
<pre class="calibre14">```
public <span class="token2">function</span> <span class="token3">cart</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span>
$data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">getCart</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">addBody</span><span class="token1">(</span><span class="token">-</span><span class="token6">140</span><span class="token1">,</span> $data<span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span>$this<span class="token">-</span><span class="token">></span>typ <span class="token">==</span> <span class="token4">'json'</span><span class="token1">)</span> <span class="token1">{</span>
$new_data <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$sum <span class="token">=</span> <span class="token6">0</span><span class="token1">;</span>
$count <span class="token">=</span> $data<span class="token1">[</span><span class="token4">'count'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token3">unset</span><span class="token1">(</span>$data<span class="token1">[</span><span class="token4">'count'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span>
$new_data<span class="token1">[</span><span class="token4">'count'</span><span class="token1">]</span> <span class="token">=</span> $count<span class="token1">;</span>
$cart_list <span class="token">=</span> <span class="token3">array_values</span><span class="token1">(</span>$data<span class="token1">)</span><span class="token1">;</span>
$new_data<span class="token1">[</span><span class="token4">'cart_list'</span><span class="token1">]</span> <span class="token">=</span> $cart_list<span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span> <span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$cart_list<span class="token1">)</span> <span class="token1">)</span> <span class="token1">{</span>
foreach <span class="token1">(</span>$cart_list as $key <span class="token">=</span><span class="token">></span> $val<span class="token1">)</span> <span class="token1">{</span>
foreach <span class="token1">(</span>$val<span class="token1">[</span><span class="token4">'goods'</span><span class="token1">]</span> as $k <span class="token">=</span><span class="token">></span> $v<span class="token1">)</span> <span class="token1">{</span>
$sum <span class="token">+</span><span class="token">=</span> $v<span class="token1">[</span><span class="token4">'goods_num'</span><span class="token1">]</span> <span class="token">*</span> $v<span class="token1">[</span><span class="token4">'now_price'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
<span class="token1">}</span>
$new_data<span class="token1">[</span><span class="token4">'sum'</span><span class="token1">]</span> <span class="token">=</span> $sum<span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">addBody</span><span class="token1">(</span><span class="token">-</span><span class="token6">140</span><span class="token1">,</span> $new_data<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span><span class="token2">else</span><span class="token1">{</span>
include $this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">getView</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
$this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">addBody</span><span class="token1">(</span><span class="token">-</span><span class="token6">140</span><span class="token1">,</span>$new_data<span class="token1">)</span><span class="token1">;</span> <span class="token5">//返回数据</span>
include $this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">getView</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token5">//加载页面</span>
<span class="token1">}</span>
```
```
如果是加载页面,则页面的路径为 `shop/views/default/Buyer/CartCtl/cart.php`
在文件中有几种表示路径的方法:
```
<pre class="calibre14">```
<span class="token"><</span><span class="token">?</span><span class="token">=</span>$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span>js<span class="token">?</span><span class="token">></span><span class="token">/</span>cart<span class="token1">.</span>js <span class="token5">//对应文件 shop/static/default/js/cart.js</span>
<span class="token"><</span><span class="token">?</span><span class="token">=</span> $this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span>js_com <span class="token">?</span><span class="token">></span><span class="token">/</span>sppl<span class="token1">.</span>js <span class="token5">//shop/static/common/js/sppl.js</span>
<span class="token"><</span><span class="token">?</span><span class="token">=</span> $this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span>css <span class="token">?</span><span class="token">></span><span class="token">/</span>tips<span class="token1">.</span>css <span class="token5">//shop/static/default/css/tips.css</span>
<span class="token"><</span><span class="token">?</span><span class="token">=</span>$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span>img<span class="token">?</span><span class="token">></span><span class="token">/</span>mask<span class="token1">.</span>png <span class="token5">//shop/static/default/images/mask.png</span>
```
```
三、model方法(对数据表的操作)
例子:
```
<pre class="calibre14">```
shop<span class="token">/</span>models<span class="token">/</span>Cart<span class="token1">.</span>php
shop<span class="token">/</span>models<span class="token">/</span>CartModel<span class="token1">.</span>php
```
```
`Cart.php`与`CartModel.php`这两个文件都是对购物车表进行操作的文件。Cart.php文件主要定义了增删改查这四个方法。
```
<pre class="calibre14">```
<span class="token"><</span><span class="token">?</span>php <span class="token2">if</span> <span class="token1">(</span><span class="token">!</span><span class="token3">defined</span><span class="token1">(</span><span class="token4">'ROOT_PATH'</span><span class="token1">)</span><span class="token1">)</span>
<span class="token1">{</span>
<span class="token3">exit</span><span class="token1">(</span><span class="token4">'No Permission'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/**
*
*
* @category Framework
* @package __init__
* @author Yf <service@yuanfeng.cn>
* @copyright Copyright (c) 2010, 朱羽婷
* @version 1.0
* @todo
*/</span>
class <span class="token3">Cart</span> extends <span class="token3">Yf_Model</span>
<span class="token1">{</span>
public $_cacheKeyPrefix <span class="token">=</span> <span class="token4">'c|Cart|'</span><span class="token1">;</span>
public $_cacheName <span class="token">=</span> <span class="token4">'cart'</span><span class="token1">;</span>
public $_tableName <span class="token">=</span> <span class="token4">'cart'</span><span class="token1">;</span>
public $_tablePrimaryKey <span class="token">=</span> <span class="token4">'cart_id'</span><span class="token1">;</span>
<span class="token5">/**
* @param string $user User Object
* @var string $db_id 指定需要连接的数据库Id
* @return void
*/</span>
public <span class="token2">function</span> <span class="token3">__construct</span><span class="token1">(</span><span class="token">&</span>$db_id <span class="token">=</span> <span class="token4">'shop'</span><span class="token1">,</span> <span class="token">&</span>$user <span class="token">=</span> <span class="token2">null</span><span class="token1">)</span>
<span class="token1">{</span>
$this<span class="token">-</span><span class="token">></span>_tableName <span class="token">=</span> TABEL_PREFIX <span class="token1">.</span> $this<span class="token">-</span><span class="token">></span>_tableName<span class="token1">;</span>
parent<span class="token1">:</span><span class="token1">:</span><span class="token3">__construct</span><span class="token1">(</span>$db_id<span class="token1">,</span> $user<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/**
* @param int $config_key 主键值
* @return array $rows 返回的查询内容
* @access public
*/</span>
public <span class="token2">function</span> <span class="token3">getCart</span><span class="token1">(</span>$cart_id <span class="token">=</span> <span class="token2">null</span><span class="token1">,</span> $sort_key_row <span class="token">=</span> <span class="token2">null</span><span class="token1">)</span>
<span class="token1">{</span>
$rows <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$rows <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">get</span><span class="token1">(</span>$cart_id<span class="token1">,</span> $sort_key_row<span class="token1">)</span><span class="token1">;</span>
<span class="token2">return</span> $rows<span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/**
* 插入
* @param array $field_row 插入数据信息
* @param bool $return_insert_id 是否返回inset id
* @param array $field_row 信息
* @return bool 是否成功
* @access public
*/</span>
public <span class="token2">function</span> <span class="token3">addCart</span><span class="token1">(</span>$field_row<span class="token1">,</span> $return_insert_id <span class="token">=</span> <span class="token6">false</span><span class="token1">)</span>
<span class="token1">{</span>
$add_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">add</span><span class="token1">(</span>$field_row<span class="token1">,</span> $return_insert_id<span class="token1">)</span><span class="token1">;</span>
<span class="token5">//$this->removeKey($config_key);</span>
<span class="token2">return</span> $add_flag<span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/**
* 根据主键更新表内容
* @param mix $config_key 主键
* @param array $field_row key=>value数组
* @return bool $update_flag 是否成功
* @access public
*/</span>
public <span class="token2">function</span> <span class="token3">editCart</span><span class="token1">(</span>$cart_id <span class="token">=</span> <span class="token2">null</span><span class="token1">,</span> $field_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span> $flag <span class="token">=</span> <span class="token6">true</span><span class="token1">)</span>
<span class="token1">{</span>
$update_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">edit</span><span class="token1">(</span>$cart_id<span class="token1">,</span> $field_row<span class="token1">,</span> $flag<span class="token1">)</span><span class="token1">;</span>
<span class="token2">return</span> $update_flag<span class="token1">;</span>
<span class="token1">}</span>
public <span class="token2">function</span> <span class="token3">editCartNum</span><span class="token1">(</span>$cart_id <span class="token">=</span> <span class="token2">null</span><span class="token1">,</span> $field_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">)</span>
<span class="token1">{</span>
$update_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">edit</span><span class="token1">(</span>$cart_id<span class="token1">,</span> $field_row<span class="token1">)</span><span class="token1">;</span>
<span class="token2">return</span> $update_flag<span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/**
* 更新单个字段
* @param mix $config_key
* @param array $field_name
* @param array $field_value_new
* @param array $field_value_old
* @return bool $update_flag 是否成功
* @access public
*/</span>
public <span class="token2">function</span> <span class="token3">editCartSingleField</span><span class="token1">(</span>$cart_id<span class="token1">,</span> $company<span class="token1">)</span>
<span class="token1">{</span>
$update_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">editSingleField</span><span class="token1">(</span>$cart_id<span class="token1">,</span> $company<span class="token1">)</span><span class="token1">;</span>
<span class="token2">return</span> $update_flag<span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/**
* 删除操作
* @param int $config_key
* @return bool $del_flag 是否成功
* @access public
*/</span>
public <span class="token2">function</span> <span class="token3">removeCart</span><span class="token1">(</span>$cart_id<span class="token1">)</span>
<span class="token1">{</span>
$del_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">remove</span><span class="token1">(</span>$cart_id<span class="token1">)</span><span class="token1">;</span>
<span class="token5">//$this->removeKey($config_key);</span>
<span class="token2">return</span> $del_flag<span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
<span class="token">?</span><span class="token">></span>
```
```
*商城中只能单表查询,不能多表联查。
*`Cart.php`只写最基本的增删改查方法,最好不要把其他的方法写入这个文件。
* editCart方法中的第3个参数表示的是修改数字符号为“+=” 还是“=”,例如editCart(1,array(goods\_num=>3),true)),表示的是goods\_num = goods\_num + 3。editCart(1,array(goods\_num=>3),false)),表示的是goods\_num = 3。
几种经常使用的查找方法
`listByWhere` 返回带分页的数据
`getOne` 根据主键查找数据
`getByWhere` 根据条件查找数据
更多方法可以在`libraries/Yf/Model.php`中查找。
四、controller方法
例子:获取当前用户的购物车数据
地址为:`http://shop.bbc-builder.com/index.php?ctl=Buyer_Cart&met=cart`
CartCtl.php中定义的cart方法上面已经写出。其中`$data = $this->getCart();`的getCart()方法如下:
```
<pre class="calibre14">```
<span class="token5">/**
* 获取购物车列表
*
* @author Zhuyt
*/</span>
public <span class="token2">function</span> <span class="token3">getCart</span><span class="token1">(</span><span class="token1">)</span>
<span class="token1">{</span>
$user_id <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$row<span class="token1">[</span><span class="token4">'user_id'</span><span class="token1">]</span><span class="token1">;</span>
$Goods_BaseModel <span class="token">=</span> <span class="token2">new</span> <span class="token3">Goods_BaseModel</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$cord_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$order_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$cond_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">'user_id'</span> <span class="token">=</span><span class="token">></span> $user_id<span class="token1">)</span><span class="token1">;</span>
$order_row<span class="token1">[</span><span class="token4">'cart_id'</span><span class="token1">]</span> <span class="token">=</span> <span class="token4">'DESC'</span><span class="token1">;</span>
$data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>cartModel<span class="token">-</span><span class="token">></span><span class="token3">getCardList</span><span class="token1">(</span>$cond_row<span class="token1">,</span> $order_row<span class="token1">)</span><span class="token1">;</span>
foreach <span class="token1">(</span>$data as $key <span class="token">=</span><span class="token">></span> $value<span class="token1">)</span> <span class="token1">{</span>
$goods_detail <span class="token">=</span> $Goods_BaseModel<span class="token">-</span><span class="token">></span><span class="token3">getGoodsDetailInfoByGoodId</span><span class="token1">(</span>$value<span class="token1">[</span><span class="token4">'goods'</span><span class="token1">]</span><span class="token1">[</span><span class="token6">0</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'goods_id'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span><span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$goods_detail<span class="token1">[</span><span class="token4">'common_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'common_spec_name'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span>
<span class="token5">//商品规格颜色图</span>
<span class="token2">if</span> <span class="token1">(</span><span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$goods_detail<span class="token1">[</span><span class="token4">'common_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'common_spec_value_color'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span>
$data<span class="token1">[</span>$key<span class="token1">]</span><span class="token1">[</span><span class="token4">'goods'</span><span class="token1">]</span><span class="token1">[</span><span class="token6">0</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'goods_image'</span><span class="token1">]</span> <span class="token">=</span> $goods_detail<span class="token1">[</span><span class="token4">'common_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'common_spec_value_color'</span><span class="token1">]</span><span class="token1">[</span>$value<span class="token1">[</span><span class="token4">'goods'</span><span class="token1">]</span><span class="token1">[</span><span class="token6">0</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'color_id'</span><span class="token1">]</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
<span class="token1">}</span>
<span class="token2">if</span> <span class="token1">(</span>$data<span class="token1">)</span> <span class="token1">{</span>
$status <span class="token">=</span> <span class="token6">200</span><span class="token1">;</span>
$msg <span class="token">=</span> <span class="token3">__</span><span class="token1">(</span><span class="token4">'success'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span>
$status <span class="token">=</span> <span class="token6">250</span><span class="token1">;</span>
$msg <span class="token">=</span> <span class="token3">__</span><span class="token1">(</span><span class="token4">'failure'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
$this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">addBody</span><span class="token1">(</span><span class="token">-</span><span class="token6">140</span><span class="token1">,</span> $data<span class="token1">,</span> $msg<span class="token1">,</span> $status<span class="token1">)</span><span class="token1">;</span>
<span class="token2">return</span> $data<span class="token1">;</span>
<span class="token1">}</span>
```
```
使用model方法先实例化对象。
```
<pre class="calibre14">```
$this<span class="token">-</span><span class="token">></span>cartModel <span class="token">=</span> <span class="token2">new</span> <span class="token3">CartModel</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
```
```
获取数据后根据实际需求决定是返回数据还是加载页面。
五、view中显示数据
例子:购物车页面
```
<pre class="calibre14">```
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"cart_goods"</span><span class="token">></span>
<span class="token"><</span>ul class<span class="token">=</span><span class="token4">'cart_goods_head clearfix'</span><span class="token">></span><span class="token"><</span>li class<span class="token">=</span><span class="token4">"done"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'操作'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>li<span class="token">></span>
<span class="token"><</span>li class<span class="token">=</span><span class="token4">"price_all"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'小计'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token1">(</span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>Web_ConfigModel<span class="token1">:</span><span class="token1">:</span><span class="token3">value</span><span class="token1">(</span><span class="token4">'monetary_unit'</span><span class="token1">)</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token1">)</span><span class="token"><</span><span class="token">/</span>li<span class="token">></span>
<span class="token"><</span>li class<span class="token">=</span><span class="token4">"goods_num"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'数量'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>li<span class="token">></span>
<span class="token"><</span>li class<span class="token">=</span><span class="token4">"goods_price"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'单价'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token1">(</span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>Web_ConfigModel<span class="token1">:</span><span class="token1">:</span><span class="token3">value</span><span class="token1">(</span><span class="token4">'monetary_unit'</span><span class="token1">)</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token1">)</span><span class="token"><</span><span class="token">/</span>li<span class="token">></span>
<span class="token"><</span>li class<span class="token">=</span><span class="token4">"goods_name"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'商品'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>li<span class="token">></span>
<span class="token"><</span>li class<span class="token">=</span><span class="token4">"cart_goods_all cart-checkbox "</span> style<span class="token">=</span><span class="token4">"float:left;"</span><span class="token">></span><span class="token"><</span>input class<span class="token">=</span><span class="token4">"checkall"</span> type<span class="token">=</span><span class="token4">"checkbox"</span> data<span class="token">-</span>type<span class="token">=</span><span class="token4">"all"</span><span class="token">></span><span class="token"><</span>div class<span class="token">=</span><span class="token4">"select_all"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'全选'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>div<span class="token">></span><span class="token"><</span><span class="token">/</span>li<span class="token">></span>
<span class="token"><</span><span class="token">/</span>ul<span class="token">></span>
<span class="token"><</span>form id<span class="token">=</span><span class="token4">"form"</span> action<span class="token">=</span><span class="token4">"?ctl=Buyer_Cart&met=confirm"</span> method<span class="token">=</span><span class="token4">'post'</span><span class="token">></span>
<span class="token"><</span>ul class<span class="token">=</span><span class="token4">"cart_goods_list clearfix"</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token3">foreach</span><span class="token1">(</span>$data as $key<span class="token">=</span><span class="token">></span>$val<span class="token1">)</span><span class="token1">{</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span>li class<span class="token">=</span><span class="token4">"carts_content"</span><span class="token">></span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"bus_imfor clearfix"</span><span class="token">></span>
<span class="token"><</span>p class<span class="token">=</span><span class="token4">"bus_name"</span><span class="token">></span>
<span class="token"><</span>input class<span class="token">=</span><span class="token4">"checkshop checkitem"</span> type<span class="token">=</span><span class="token4">"checkbox"</span> data<span class="token">-</span>type<span class="token">=</span><span class="token4">"all"</span><span class="token">></span>
<span class="token"><</span>span<span class="token">></span><span class="token"><</span>i class<span class="token">=</span><span class="token4">"iconfont icon-icoshop"</span><span class="token">></span><span class="token"><</span><span class="token">/</span>i<span class="token">></span><span class="token"><</span>a href<span class="token">=</span><span class="token4">"<?= Yf_Registry::get('url') ?>?ctl=Shop&met=index&id=<?=($key)?>"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>$val<span class="token1">[</span><span class="token4">'shop_name'</span><span class="token1">]</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span><span class="token">/</span>span<span class="token">></span>
<span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token"><</span>table id<span class="token">=</span><span class="token4">"table_list"</span> class<span class="token">=</span><span class="token4">"table_list"</span><span class="token">></span>
<span class="token"><</span>tbody class<span class="token">=</span><span class="token4">"rel_good_infor"</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token3">foreach</span><span class="token1">(</span>$val<span class="token1">[</span><span class="token4">'goods'</span><span class="token1">]</span> as $k<span class="token">=</span><span class="token">></span>$v<span class="token1">)</span><span class="token1">{</span> <span class="token">?</span><span class="token">></span>
<span class="token"><</span>tr class<span class="token">=</span><span class="token4">"row_line"</span><span class="token">></span>
<span class="token"><</span>td class<span class="token">=</span><span class="token4">"goods_sel cart-checkbox"</span><span class="token">></span>
<span class="token"><</span>p<span class="token">></span>
<span class="token"><</span>input class<span class="token">=</span><span class="token4">"checkitem"</span> type<span class="token">=</span><span class="token4">"checkbox"</span> name<span class="token">=</span><span class="token4">"product_id[]"</span> value<span class="token">=</span><span class="token4">"<?=($v['cart_id'])?>"</span> <span class="token"><</span><span class="token">?</span>php <span class="token2">if</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'IsHaveBuy'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">{</span><span class="token">?</span><span class="token">></span>disabled<span class="token">=</span><span class="token4">""</span> title<span class="token">=</span><span class="token4">"您已达限购数量"</span> <span class="token"><</span><span class="token">?</span>php <span class="token1">}</span><span class="token">?</span><span class="token">></span> <span class="token">></span>
<span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token"><</span><span class="token">/</span>td<span class="token">></span>
<span class="token"><</span>td class<span class="token">=</span><span class="token4">"goods_img"</span><span class="token">></span><span class="token"><</span>img src<span class="token">=</span><span class="token4">"<?=($v['goods_base']['goods_image'])?>"</span><span class="token">/</span><span class="token">></span><span class="token"><</span><span class="token">/</span>td<span class="token">></span>
<span class="token"><</span>td class<span class="token">=</span><span class="token4">"goods_name_reset"</span><span class="token">></span>
<span class="token"><</span>a target<span class="token">=</span><span class="token4">"_blank"</span> href<span class="token">=</span><span class="token4">"<?= Yf_Registry::get('url') ?>?ctl=Goods_Goods&met=goods&gid=<?=($v['goods_base']['goods_id'])?>"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'goods_name'</span><span class="token1">]</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token2">if</span><span class="token1">(</span><span class="token3">isset</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'promotion_type'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">:</span> <span class="token">?</span><span class="token">></span>
<span class="token"><</span>p class<span class="token">=</span><span class="token4">"sal_price"</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token2">if</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'promotion_type'</span><span class="token1">]</span> <span class="token">==</span> <span class="token4">'groupbuy'</span> <span class="token">&&</span> $v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'down_price'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">:</span> <span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'团购,直降:'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">format_money</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'down_price'</span><span class="token1">]</span><span class="token1">)</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php endif<span class="token1">;</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token2">if</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'promotion_type'</span><span class="token1">]</span> <span class="token">==</span> <span class="token4">'xianshi'</span> <span class="token">&&</span> $v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'down_price'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">:</span> <span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'限时折扣,直降:'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">format_money</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'down_price'</span><span class="token1">]</span><span class="token1">)</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php endif<span class="token1">;</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token"><</span><span class="token">?</span>php endif<span class="token1">;</span> <span class="token">?</span><span class="token">></span>
<span class="token"><</span>p<span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token2">if</span><span class="token1">(</span><span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'spec'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">{</span><span class="token3">foreach</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'spec'</span><span class="token1">]</span> as $sk <span class="token">=</span><span class="token">></span> $sv<span class="token1">)</span><span class="token1">{</span> <span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>$sv<span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token">&</span>nbsp<span class="token1">;</span><span class="token">&</span>nbsp<span class="token1">;</span>
<span class="token"><</span><span class="token">?</span>php <span class="token1">}</span><span class="token1">}</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token"><</span><span class="token">/</span>td<span class="token">></span>
<span class="token"><</span>td class<span class="token">=</span><span class="token4">"goods_price"</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token2">if</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'old_price'</span><span class="token1">]</span> <span class="token">></span> <span class="token6">0</span><span class="token1">)</span><span class="token1">{</span><span class="token">?</span><span class="token">></span><span class="token"><</span>p class<span class="token">=</span><span class="token4">"ori_price"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'old_price'</span><span class="token1">]</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span><span class="token"><</span><span class="token">?</span>php <span class="token1">}</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span>p class<span class="token">=</span><span class="token4">"now_price"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'now_price'</span><span class="token1">]</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token"><</span><span class="token">/</span>td<span class="token">></span>
<span class="token"><</span>td class<span class="token">=</span><span class="token4">"goods_num"</span><span class="token">></span>
<span class="token"><</span><span class="token">?</span>php
<span class="token2">if</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'buy_limit'</span><span class="token1">]</span> <span class="token">&&</span> <span class="token">!</span>$v<span class="token1">[</span><span class="token4">'IsHaveBuy'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
$data_max <span class="token">=</span> $v<span class="token1">[</span><span class="token4">'buy_residue'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$data_max <span class="token">=</span> $v<span class="token1">[</span><span class="token4">'goods_base'</span><span class="token1">]</span><span class="token1">[</span><span class="token4">'goods_stock'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token">?</span><span class="token">></span>
<span class="token"><</span>a class<span class="token">=</span><span class="token4">"<?php if($v['goods_num'] == 1){?>no_<?php }?>reduce"</span> <span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'-'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span>input id<span class="token">=</span><span class="token4">"nums"</span> data<span class="token">-</span>id<span class="token">=</span><span class="token4">"<?=($v['cart_id'])?>"</span> data<span class="token">-</span>max<span class="token">=</span><span class="token4">"<?=($data_max)?>"</span> value<span class="token">=</span><span class="token4">"<?=($v['goods_num'])?>"</span><span class="token">></span><span class="token"><</span>a class<span class="token">=</span><span class="token4">"<?php if($data_max <= 1){?>no_<?php }?>add"</span> <span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'+'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span>
<span class="token"><</span><span class="token">/</span>td<span class="token">></span>
<span class="token"><</span>td class<span class="token">=</span><span class="token4">"price_all cell<?=($v['cart_id'])?>"</span><span class="token">></span>
<span class="token"><</span>span class<span class="token">=</span><span class="token4">"subtotal"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token1">(</span>$v<span class="token1">[</span><span class="token4">'sumprice'</span><span class="token1">]</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>span<span class="token">></span>
<span class="token"><</span><span class="token">/</span>td<span class="token">></span>
<span class="token"><</span>td class<span class="token">=</span><span class="token4">"done del"</span><span class="token">></span><span class="token"><</span>a data<span class="token">-</span>param<span class="token">=</span><span class="token4">"{'ctl':'Buyer_Cart','met':'delCartByCid','id':'<?=($v['cart_id'])?>'}"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">_</span><span class="token1">(</span><span class="token4">'删除'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span><span class="token">/</span>td<span class="token">></span>
<span class="token"><</span><span class="token">/</span>tr<span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token1">}</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>tbody<span class="token">></span>
<span class="token"><</span><span class="token">/</span>table<span class="token">></span>
<span class="token"><</span><span class="token">/</span>li<span class="token">></span>
<span class="token"><</span><span class="token">?</span>php <span class="token1">}</span><span class="token">?</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>ul<span class="token">></span>
<span class="token"><</span><span class="token">/</span>form<span class="token">></span>
```
```
五、其他
(1)在shop中调用其他项目的方法 `get_url_with_encrypt`
定义方法的文件:`libraries\__init__.php`
```
<pre class="calibre14">```
<span class="token5">//可以判断请求时间是否超过某个期限</span>
<span class="token2">function</span> <span class="token3">get_url_with_encrypt</span><span class="token1">(</span>$key<span class="token1">,</span> $url<span class="token1">,</span> $formvars <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span> $typ <span class="token">=</span> <span class="token4">'JSON'</span><span class="token1">,</span> $method <span class="token">=</span> <span class="token4">'POST'</span><span class="token1">)</span>
<span class="token1">{</span>
$formvars<span class="token1">[</span><span class="token4">'rtime'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">get_time</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$hash_row <span class="token">=</span> $formvars<span class="token1">;</span>
<span class="token3">array_multiksort</span><span class="token1">(</span>$hash_row<span class="token1">,</span> SORT_STRING<span class="token1">)</span><span class="token1">;</span>
$hash_row<span class="token1">[</span><span class="token4">'key'</span><span class="token1">]</span> <span class="token">=</span> $key<span class="token1">;</span>
$tmp_str <span class="token">=</span> <span class="token3">http_build_query</span><span class="token1">(</span>$hash_row<span class="token1">)</span><span class="token1">;</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span><span class="token4">'$tmp_str:'</span> <span class="token1">.</span> $tmp_str<span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'get_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span><span class="token4">'$url:'</span> <span class="token1">.</span> $url<span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'get_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
$formvars<span class="token1">[</span><span class="token4">"token"</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">md5</span><span class="token1">(</span>$tmp_str<span class="token1">)</span><span class="token1">;</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span>$hash_row<span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'get_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span>$formvars<span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'get_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
$rs <span class="token">=</span> <span class="token3">get_url</span><span class="token1">(</span>$url<span class="token1">,</span> $formvars<span class="token1">,</span> $typ<span class="token1">,</span> $method<span class="token1">)</span><span class="token1">;</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span>$rs<span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'get_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">return</span> $rs<span class="token1">;</span>
<span class="token1">}</span>
```
```
例如:
在shop中调用paycenter中的用户信息。
```
<pre class="calibre14">```
<span class="token5">//会员的钱</span>
$key <span class="token">=</span> Yf_Registry<span class="token1">:</span><span class="token1">:</span><span class="token3">get</span><span class="token1">(</span><span class="token4">'shop_api_key'</span><span class="token1">)</span><span class="token1">;</span>
$formvars <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$user_id <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$userId<span class="token1">;</span>
$formvars<span class="token1">[</span><span class="token4">'user_id'</span><span class="token1">]</span> <span class="token">=</span> $user_id<span class="token1">;</span>
$formvars<span class="token1">[</span><span class="token4">'app_id'</span><span class="token1">]</span> <span class="token">=</span> Yf_Registry<span class="token1">:</span><span class="token1">:</span><span class="token3">get</span><span class="token1">(</span><span class="token4">'shop_app_id'</span><span class="token1">)</span><span class="token1">;</span>
$money_row <span class="token">=</span> <span class="token3">get_url_with_encrypt</span><span class="token1">(</span>$key<span class="token1">,</span> <span class="token3">sprintf</span><span class="token1">(</span><span class="token4">'%sindex.php?ctl=Api_User_Info&met=getUserResourceInfo&typ=json'</span><span class="token1">,</span>
Yf_Registry<span class="token1">:</span><span class="token1">:</span><span class="token3">get</span><span class="token1">(</span><span class="token4">'paycenter_api_url'</span><span class="token1">)</span><span class="token1">)</span><span class="token1">,</span> $formvars<span class="token1">)</span><span class="token1">;</span>
```
```
在shop中验证接口合法性的方法`check_url_with_encrypt`
定义方法的文件:`libraries\__init__.php`
```
<pre class="calibre14">```
<span class="token2">function</span> <span class="token3">check_url_with_encrypt</span><span class="token1">(</span>$key<span class="token1">,</span> $formvars <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">)</span>
<span class="token1">{</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span>$formvars<span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'check_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
$token <span class="token">=</span> $formvars<span class="token1">[</span><span class="token4">'token'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token3">unset</span><span class="token1">(</span>$formvars<span class="token1">[</span><span class="token4">'token'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span>
$hash_row <span class="token">=</span> $formvars<span class="token1">;</span>
<span class="token3">array_multiksort</span><span class="token1">(</span>$hash_row<span class="token1">,</span> SORT_STRING<span class="token1">)</span><span class="token1">;</span>
$hash_row<span class="token1">[</span><span class="token4">'key'</span><span class="token1">]</span> <span class="token">=</span> $key<span class="token1">;</span>
$tmp_str <span class="token">=</span> <span class="token3">http_build_query</span><span class="token1">(</span>$hash_row<span class="token1">)</span><span class="token1">;</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span><span class="token4">'$tmp_str:'</span> <span class="token1">.</span> $tmp_str<span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'check_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
Yf_Log<span class="token1">:</span><span class="token1">:</span><span class="token3">log</span><span class="token1">(</span><span class="token4">'md5-key:'</span> <span class="token1">.</span> <span class="token3">md5</span><span class="token1">(</span>$tmp_str<span class="token1">)</span><span class="token1">,</span> Yf_Log<span class="token1">:</span><span class="token1">:</span>INFO<span class="token1">,</span> <span class="token4">'check_url_with_encrypt'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token5">//可以判断请求时间是否超过某个期限, 1分钟内</span>
<span class="token2">if</span> <span class="token1">(</span><span class="token1">(</span><span class="token3">get_time</span><span class="token1">(</span><span class="token1">)</span> <span class="token">-</span> $hash_row<span class="token1">[</span><span class="token4">'rtime'</span><span class="token1">]</span> <span class="token"><</span> <span class="token6">60000</span><span class="token1">)</span> <span class="token">&&</span> $token <span class="token">==</span> <span class="token3">md5</span><span class="token1">(</span>$tmp_str<span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span>
<span class="token2">return</span> <span class="token6">true</span><span class="token1">;</span>
<span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span>
<span class="token2">return</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
```
```
例如:`shop\controllers\Api\Controller.php`
```
<pre class="calibre14">```
<span class="token2">if</span> <span class="token1">(</span><span class="token">!</span><span class="token3">check_url_with_encrypt</span><span class="token1">(</span>$key<span class="token1">,</span> $data<span class="token1">)</span><span class="token1">)</span><span class="token1">{</span>
$this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">setError</span><span class="token1">(</span><span class="token3">__</span><span class="token1">(</span><span class="token4">'API接口有误,请确保APP KEY及APP ID正确'</span><span class="token1">)</span><span class="token1">,</span> <span class="token6">301</span><span class="token1">)</span><span class="token1">;</span> $d <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">getDataRows</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$protocol_data <span class="token">=</span> Yf_Data<span class="token1">:</span><span class="token1">:</span><span class="token3">encodeProtocolData</span><span class="token1">(</span>$d<span class="token1">)</span><span class="token1">;</span>
echo $protocol_data<span class="token1">;</span> <span class="token3">exit</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
底层防SQL注入:
```
<pre class="calibre14">```
<span class="token5">/**
* 转义字符函数
*
* @param mixed $content contents should be addslashes
*
* @return mixed $content
*
*/</span>
<span class="token2">function</span> <span class="token3">quotes</span><span class="token1">(</span><span class="token">&</span>$content<span class="token1">)</span>
<span class="token1">{</span>
<span class="token2">if</span> <span class="token1">(</span><span class="token3">is_array</span><span class="token1">(</span>$content<span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span>
foreach <span class="token1">(</span>$content as $key <span class="token">=</span><span class="token">></span> $value<span class="token1">)</span> <span class="token1">{</span>
$content<span class="token1">[</span>$key<span class="token1">]</span> <span class="token">=</span> <span class="token3">quotes</span><span class="token1">(</span>$value<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span>
$content <span class="token">=</span> <span class="token3">addslashes</span><span class="token1">(</span>$content<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">return</span> $content<span class="token1">;</span>
<span class="token1">}</span>
```
```
在`libraries\Yf\Model.php`文件的174行
```
<pre class="calibre15">```
$value <span class="token">=</span> <span class="token3">htmlspecialchars</span><span class="token1">(</span>$value<span class="token1">)</span><span class="token1">;</span>
```
```
- 序言
- 系统要求
- 版本更新日志
- 远丰商城技术对接说明
- 开发指导
- 框架内容
- 基础
- 开发规范
- 目录结构
- 架构
- 架构总览
- 数据库
- 数据库连接
- 基本使用
- 缓存
- 配置
- 路由
- 数据字典
- ucenter
- shop
- paycenter
- ucenter_admin
- shop_admin
- paycenter_admin
- 通讯内容
- 商家中心
- 顶部导航栏
- 店铺信息栏
- 店铺及商品提示栏
- 交易提示栏
- 销售情况统计栏
- 单品销量排行栏
- 店铺运营推广栏
- 平台联系方式栏
- 订单物流
- 商品
- 商品列表
- 商品详情
- 商品发布与编辑
- 分销商品
- 关联版式
- 商品规格
- 图片空间
- 淘宝导入
- 订单流程
- 交易订单
- 订单退款/退货
- 促销
- 团购管理
- 加价购
- 限时折扣
- 满即送
- 代金券管理
- 分销
- 店铺
- 店铺设置
- 自销产品供应商
- 实体店铺
- 品牌申请
- 店铺信息
- 消费者保障服务
- 门店账号
- 分销商--产品供应商
- 分销明细
- 批发市场
- 售后服务
- 咨询管理
- 投诉管理
- 退款管理
- 退货管理
- 云方案架构
- 负载集群
- 云存储
- 接口
- Api接口说明
- 品牌
- 商品规格
- 商品类型
- 商品分类
- 商品
- 订单
- 商品/店铺收藏
- 足迹
- 退款及退货
- 商家店铺
- 会员
- 入驻协议
- 订单接口
- 商品接口
- 订单物流接口
- 商家中心接口
- 促销接口
- 快递鸟物流接口
- 代金券接口
- 首页版块
- 团购
- 平台红包
- 限时折扣接口
- 拼团接口
- wap首页模板
- 杂项
- 远程上传图片
- JS
- 银联支付
- 多语言
- 商品评分
- 图片加载
- 买家申请退款退货
- 商家退款退货
- 平台退款退货
- 添加发票
- 提交订单
- 确认订单
- 运费销售区域
- 获取会员地址
- 充值
- 导出XLS
- 商城系统集成
- 多语言实现
- 三级分销推广链接发展推广员
- app.ini.php
- 去分销
- 版本更新
- 物流支持
- 运营人员建议
- 业务逻辑
- 统计结算
- 客服消息
- 账号
- 三级分销
- IM
- 配置
- 平台帐号
- 活动数据表说明