切换导航条
此项目
正在载入...
登录
root
/
Health
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
魏强
5 years ago
提交
63078cac88684f61eb7dbcf95274893d38c8885f
1 个父辈
281aabf1
online
隐藏空白字符变更
内嵌
并排对比
正在显示
12 个修改的文件
包含
574 行增加
和
495 行删除
addons/qiniu/config.php
application/admin/controller/Goods.php
application/admin/lang/zh-cn/goods.php
application/admin/model/Goods.php
application/admin/view/goods/add.html
application/admin/view/goods/edit.html
application/api/controller/Clock.php
application/api/controller/Common.php
application/api/controller/Shop.php
application/api/controller/User.php
application/extra/site.php
public/assets/js/backend/goods.js
addons/qiniu/config.php
查看文件 @
63078ca
...
...
@@ -74,7 +74,7 @@ return array (
'content'
=>
array
(
),
'value'
=>
'http://
pyffam7jw.bkt.clouddn.com
'
,
'value'
=>
'http://
ys.qiniu.brotop.cn
'
,
'rule'
=>
'required'
,
'msg'
=>
''
,
'tip'
=>
'未绑定CDN的话可使用七牛分配的测试域名'
,
...
...
application/admin/controller/Goods.php
查看文件 @
63078ca
...
...
@@ -22,7 +22,7 @@ class Goods extends Backend
{
parent
::
_initialize
();
$this
->
model
=
new
\app\admin\model\Goods
;
$this
->
view
->
assign
(
"goodDataList"
,
$this
->
model
->
getGoodDataList
());
}
/**
...
...
application/admin/lang/zh-cn/goods.php
查看文件 @
63078ca
...
...
@@ -9,5 +9,9 @@ return [
'Show_switch'
=>
'上下架'
,
'Createtime'
=>
'添加时间'
,
'Weigh'
=>
'权重'
,
'Deletetime'
=>
'删除时间'
'Deletetime'
=>
'删除时间'
,
'Good_data'
=>
'商品类型'
,
'Good_data 1'
=>
'普通商品'
,
'Good_data 2'
=>
'现金商品'
,
'Money'
=>
'对应现金金额'
];
...
...
application/admin/model/Goods.php
查看文件 @
63078ca
...
...
@@ -25,9 +25,9 @@ class Goods extends Model
// 追加属性
protected
$append
=
[
'goods_avatar_text'
'good_data_text'
,
'goods_avatar_text'
];
protected
static
function
init
()
{
...
...
@@ -39,20 +39,30 @@ class Goods extends Model
public
function
getGoodsAvatarTextAttr
(
$value
,
$data
)
{
return
cdnurl
(
$data
[
'goods_avatar'
]);
}
public
function
getIndexGoods
(){
$where
[
'show_switch'
]
=
1
;
$info
=
$this
->
where
(
$where
)
->
order
(
'weigh'
,
'DESC'
)
->
paginate
(
'10'
)
->
toArray
();
return
$info
;
}
public
function
getGoodDataList
()
{
return
[
'1'
=>
__
(
'Good_data 1'
),
'2'
=>
__
(
'Good_data 2'
)];
}
public
function
getGoodDataTextAttr
(
$value
,
$data
)
{
$value
=
$value
?
$value
:
(
isset
(
$data
[
'good_data'
])
?
$data
[
'good_data'
]
:
''
);
$list
=
$this
->
getGoodDataList
();
return
isset
(
$list
[
$value
])
?
$list
[
$value
]
:
''
;
}
public
function
getIndexGoods
(){
$where
[
'show_switch'
]
=
1
;
$info
=
$this
->
where
(
$where
)
->
order
(
'weigh'
,
'DESC'
)
->
paginate
(
'10'
)
->
toArray
();
return
$info
;
}
...
...
application/admin/view/goods/add.html
查看文件 @
63078ca
...
...
@@ -23,7 +23,7 @@
<div
class=
"form-group"
>
<label
class=
"control-label col-xs-12 col-sm-2"
>
{:__('Price')}:
</label>
<div
class=
"col-xs-12 col-sm-8"
>
<input
id=
"c-price"
data-rule=
"required"
class=
"form-control"
name=
"row[price]"
type=
"number"
value=
"1
1
"
>
<input
id=
"c-price"
data-rule=
"required"
class=
"form-control"
name=
"row[price]"
type=
"number"
value=
"1"
>
</div>
</div>
<div
class=
"form-group"
>
...
...
@@ -48,6 +48,24 @@
<input
id=
"c-weigh"
data-rule=
"required"
class=
"form-control"
name=
"row[weigh]"
type=
"number"
value=
"0"
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-xs-12 col-sm-2"
>
{:__('Good_data')}:
</label>
<div
class=
"col-xs-12 col-sm-8"
>
<div
class=
"radio"
>
{foreach name="goodDataList" item="vo"}
<label
for=
"row[good_data]-{$key}"
><input
id=
"row[good_data]-{$key}"
name=
"row[good_data]"
type=
"radio"
value=
"{$key}"
{
in
name=
"key"
value=
"1"
}
checked
{/
in
}
/>
{$vo}
</label>
{/foreach}
</div>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-xs-12 col-sm-2"
>
{:__('Money')}:
</label>
<div
class=
"col-xs-12 col-sm-8"
>
<input
id=
"c-money"
data-rule=
"required"
class=
"form-control"
name=
"row[money]"
type=
"number"
value=
"0"
>
</div>
</div>
<div
class=
"form-group layer-footer"
>
<label
class=
"control-label col-xs-12 col-sm-2"
></label>
<div
class=
"col-xs-12 col-sm-8"
>
...
...
application/admin/view/goods/edit.html
查看文件 @
63078ca
...
...
@@ -48,6 +48,24 @@
<input
id=
"c-weigh"
data-rule=
"required"
class=
"form-control"
name=
"row[weigh]"
type=
"number"
value=
"{$row.weigh|htmlentities}"
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-xs-12 col-sm-2"
>
{:__('Good_data')}:
</label>
<div
class=
"col-xs-12 col-sm-8"
>
<div
class=
"radio"
>
{foreach name="goodDataList" item="vo"}
<label
for=
"row[good_data]-{$key}"
><input
id=
"row[good_data]-{$key}"
name=
"row[good_data]"
type=
"radio"
value=
"{$key}"
{
in
name=
"key"
value=
"$row.good_data"
}
checked
{/
in
}
/>
{$vo}
</label>
{/foreach}
</div>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-xs-12 col-sm-2"
>
{:__('Money')}:
</label>
<div
class=
"col-xs-12 col-sm-8"
>
<input
id=
"c-money"
data-rule=
"required"
class=
"form-control"
name=
"row[money]"
type=
"number"
value=
"{$row.money|htmlentities}"
>
</div>
</div>
<div
class=
"form-group layer-footer"
>
<label
class=
"control-label col-xs-12 col-sm-2"
></label>
<div
class=
"col-xs-12 col-sm-8"
>
...
...
application/api/controller/Clock.php
查看文件 @
63078ca
此 diff 太大无法显示。
application/api/controller/Common.php
查看文件 @
63078ca
...
...
@@ -286,7 +286,6 @@ class Common extends Api
//上传成功后将存储变更为qiniu
$attachment
->
storage
=
'qiniu'
;
$attachment
->
save
();
$this
->
success
(
"上传成功"
,
[
'url'
=>
cdnurl
(
$url
),
'save_path'
=>
$url
]);
}
else
{
$this
->
error
(
'上传失败'
);
...
...
application/api/controller/Shop.php
查看文件 @
63078ca
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2019/10/8
* Time: 18:18
*/
namespace
app\api\controller
;
use
app\admin\model\Goods
;
use
app\admin\model\Orders
;
use
app\admin\model\UserAddress
;
use
app\common\controller\Api
;
use
app\common\model\ScoreLog
;
use
think\Db
;
/**
* 积分商城接口
*/
class
Shop
extends
Api
{
protected
$noNeedLogin
=
[
'listMissionType'
];
protected
$noNeedRight
=
[
'*'
];
/**
* @ApiTitle (商品首页)
* @ApiSummary (商品首页)
* @ApiMethod (POST)
* @ApiReturnParams (name="goods_avatar_text", type="string", required=true, description="商品图片")
* @ApiReturnParams (name="good_name", type="string", required=true, description="商品名称")
* @ApiReturnParams (name="price", type="string", required=true, description="商品价格")
* @ApiReturnParams (name="id", type="string", required=true, description="商品id")
* @ApiReturnParams (name="msg", type="string", required=true, description="提示语")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570532904",
"data": {
"total": 1,
"per_page": "10",
"current_page": 1,
"last_page": 1,
"data": [
{
"id": 1,
"goods_avatar": "/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg",
"good_name": "保湿面霜",
"price": 11,
"good_content": "保湿面霜一瓶 <img src=\"http://pyffam7jw.bkt.clouddn.com/uploads/20191008/Fs6sUDk9_iZh5Zhe-xVX8aMeI4Rn.jpg\" alt=\"\" />",
"show_switch": 1,
"createtime": 1570532123,
"weigh": 1,
"deletetime": null,
"goods_avatar_text": "http://pyffam7jw.bkt.clouddn.com/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg"
}
]
}
})
*/
public
function
index
(){
$Goods
=
new
Goods
();
$goods
=
$Goods
->
getIndexGoods
();
$this
->
success
(
''
,
$goods
);
}
/**
* @ApiTitle (商品详情)
* @ApiSummary (商品详情)
* @ApiMethod (POST)
* @ApiReturnParams (name="goods_avatar_text", type="string", required=true, description="商品图片")
* @ApiReturnParams (name="good_name", type="string", required=true, description="商品名称")
* @ApiReturnParams (name="price", type="string", required=true, description="商品价格")
* @ApiReturnParams (name="id", type="string", required=true, description="商品id")
* @ApiReturnParams (name="good_content", type="string", required=true, description="商品详情")
* @ApiReturnParams (name="msg", type="string", required=true, description="提示语")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
"id": 1,
"goods_avatar": "/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg",
"good_name": "保湿面霜",
"price": 11,
"good_content": "保湿面霜一瓶 <img src=\"http://pyffam7jw.bkt.clouddn.com/uploads/20191008/Fs6sUDk9_iZh5Zhe-xVX8aMeI4Rn.jpg\" alt=\"\" />",
"show_switch": 1,
"createtime": 1570532123,
"weigh": 1,
"deletetime": null,
"goods_avatar_text": "http://pyffam7jw.bkt.clouddn.com/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg"
}
})
*/
public
function
goodInfo
(){
$id
=
input
(
'id'
);
if
(
empty
(
$id
)){
$this
->
error
(
'缺少必要参数!'
);
}
$Goods
=
new
Goods
();
$info
=
$Goods
::
get
(
$id
)
->
toArray
();
$this
->
success
(
''
,
$info
);
}
/**
* @ApiTitle (获取地址列表)
* @ApiSummary (获取地址列表)
* @ApiMethod (POST)
* @ApiReturnParams (name="id", type="string", required=true, description="地址id")
* @ApiReturnParams (name="user_name", type="string", required=true, description="姓名")
* @ApiReturnParams (name="tel", type="string", required=true, description="电话")
* @ApiReturnParams (name="address", type="string", required=true, description="地址")
* @ApiReturnParams (name="defaultswitch", type="string", required=true, description="是否为默认地址")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
getAddress
(){
$user_id
=
$this
->
auth
->
id
;
$where
[
'user_id'
]
=
$user_id
;
$Address
=
new
UserAddress
();
$list
=
$Address
->
getAddressList
(
$where
);
$this
->
success
(
''
,
$list
);
}
/**
* @ApiTitle (获取默认地址)
* @ApiSummary (获取默认地址)
* @ApiMethod (POST)
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
getDefaultAddress
(){
$user_id
=
$this
->
auth
->
id
;
$where
[
'user_id'
]
=
$user_id
;
$where
[
'defaultswitch'
]
=
1
;
$Address
=
new
UserAddress
();
$list
=
$Address
->
getAddress
(
$where
);
$this
->
success
(
''
,
$list
);
}
/**
* @ApiTitle (创建地址)
* @ApiSummary (创建地址)
* @ApiMethod (POST)
* @ApiParams (name="name", type="string", required=true, description="姓名")
* @ApiParams (name="tel", type="string", required=true, description="电话")
* @ApiParams (name="province", type="string", required=true, description="省市")
* @ApiParams (name="address", type="string", required=true, description="详细地址")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
createAddress
(){
$user_id
=
$this
->
auth
->
id
;
$where
[
'user_id'
]
=
$user_id
;
$Address
=
new
UserAddress
();
$list
=
$Address
->
getAddress
(
$where
);
$insert
[
'user_id'
]
=
$user_id
;
$insert
[
'user_name'
]
=
input
(
'name'
);
$insert
[
'tel'
]
=
input
(
'tel'
);
$insert
[
'province'
]
=
input
(
'province'
);
$insert
[
'address'
]
=
input
(
'address'
);
$insert
[
'createtime'
]
=
time
();
if
(
empty
(
$list
)){
$insert
[
'defaultswitch'
]
=
'1'
;
}
else
{
$insert
[
'defaultswitch'
]
=
'0'
;
}
$result
=
$Address
->
insert
(
$insert
);
if
(
$result
>
0
){
$this
->
success
(
'编辑成功!'
);
}
else
{
$this
->
error
(
'编辑失败!'
);
}
}
/**
* @ApiTitle (获取地址信息)
* @ApiSummary (获取地址信息)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApireturnParams (name="user_name", type="string", required=true, description="用户名")
* @ApireturnParams (name="tel", type="string", required=true, description="电话")
* @ApireturnParams (name="address", type="string", required=true, description="地址")
* @ApireturnParams (name="defaultswitch", type="object", description="是否为默认地址1:是0:不是")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1571030416",
"data": {
"id": 2,
"user_id": 3,
"user_name": "宋国杰",
"tel": "17080088824",
"address": "鑫茂科技园",
"defaultswitch": 0,
"createtime": 1571022797
}
})
*/
public
function
getAddressInfo
(){
$map
[
'id'
]
=
input
(
'address_id'
);
$map
[
'user_id'
]
=
$this
->
auth
->
id
;
$address
=
UserAddress
::
get
(
$map
);
if
(
empty
(
$address
)){
$this
->
error
(
'地址不存在'
);
}
$this
->
success
(
''
,
$address
);
}
/**
* @ApiTitle (编辑地址)
* @ApiSummary (编辑地址)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="user_name", type="string", required=true, description="用户名")
* @ApiParams (name="tel", type="string", required=true, description="电话")
* @ApiParams (name="address", type="string", required=true, description="地址")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
editAddress
(){
$map
[
'id'
]
=
input
(
'address_id'
);
$map
[
'user_id'
]
=
$this
->
auth
->
id
;
$update
[
'user_name'
]
=
input
(
'user_name'
);
$update
[
'tel'
]
=
input
(
'tel'
);
$update
[
'address'
]
=
input
(
'address'
);
$result
=
UserAddress
::
get
(
$map
)
->
save
(
$update
);
if
(
$result
>
0
){
$this
->
success
(
'编辑成功'
);
}
else
{
$this
->
error
(
'编辑失败'
);
}
}
/**
* @ApiTitle (设置默认地址)
* @ApiSummary (设置默认地址)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
setDefaultAddress
(){
$id
=
input
(
'address_id'
);
$user_id
=
$this
->
auth
->
id
;
$map
[
'id'
]
=
$id
;
$map
[
'user_id'
]
=
$user_id
;
$update
[
'defaultswitch'
]
=
1
;
$UserAddress
=
new
UserAddress
();
$map1
[
'user_id'
]
=
$user_id
;
$map1
[
'defaultswitch'
]
=
1
;
$update1
[
'defaultswitch'
]
=
0
;
$address
=
$UserAddress
->
get
(
$map1
);
if
(
!
empty
(
$address
)){
$address
->
save
(
$update1
);
}
$UserAddress
->
get
(
$map
)
->
save
(
$update
);
$this
->
success
(
'设置成功!'
);
}
/**
* @ApiTitle (删除地址)
* @ApiSummary (删除地址)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
deleteAddress
(){
$map
[
'user_id'
]
=
$this
->
auth
->
id
;
$map
[
'id'
]
=
input
(
'address_id'
);
$one
=
UserAddress
::
get
(
$map
);
if
(
empty
(
$one
)){
$this
->
error
(
'地址不存在'
);
}
$result
=
$one
->
delete
();
if
(
$result
>
0
){
$this
->
success
(
'操作成功!'
);
}
else
{
$this
->
error
(
'操作失败!'
);
}
}
/**
* @ApiTitle (提交订单)
* @ApiSummary (提交订单)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="good_id", type="string", required=true, description="商品id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
setOrder
(){
$address_id
=
input
(
'address_id'
);
$good_id
=
input
(
'good_id'
);
if
(
empty
(
$address_id
)
||
empty
(
$good_id
)){
$this
->
error
(
'请选择地址'
);
}
/*查询是有对应地址*/
$address
=
UserAddress
::
get
(
$address_id
);
if
(
empty
(
$address
)){
$this
->
error
(
'地址不存在'
);
}
$address
=
$address
->
toArray
();
$good
=
Goods
::
get
(
$good_id
);
if
(
empty
(
$good
)){
$this
->
error
(
'商品不存在'
);
}
$good
=
$good
->
toArray
();
$user_id
=
$this
->
auth
->
id
;
$user
=
\app\admin\model\User
::
get
(
$user_id
)
->
toArray
();
if
(
$user
[
'score'
]
<
$good
[
'price'
]){
$this
->
error
(
'积分不足!'
);
}
$insert
[
'order_sn'
]
=
cmf_get_order_sn
();
$insert
[
'user_id'
]
=
$user_id
;
$insert
[
'user_name'
]
=
$address
[
'user_name'
];
$insert
[
'tel'
]
=
$address
[
'tel'
];
$insert
[
'address'
]
=
$address
[
'address'
];
$insert
[
'good_id'
]
=
$good_id
;
$insert
[
'price'
]
=
$good
[
'price'
];
$User
=
new
\app\admin\model\User
();
Db
::
startTrans
();
try
{
Orders
::
create
(
$insert
);
$User
->
where
(
'id'
,
$user_id
)
->
setDec
(
'score'
,
$good
[
'price'
]);
$insert_log
[
'user_id'
]
=
$user_id
;
$insert_log
[
'score'
]
=
0
-
$good
[
'price'
];
$insert_log
[
'memo'
]
=
'积分兑换'
;
ScoreLog
::
create
(
$insert_log
);
// 提交事务
Db
::
commit
();
}
catch
(
\Exception
$e
)
{
// 回滚事务
dump
(
$e
->
getMessage
());
Db
::
rollback
();
$this
->
error
(
'支付失败!'
);
}
$this
->
success
(
'支付成功!'
);
}
/**
* @ApiTitle (我的订单)
* @ApiSummary (我的订单)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="good_id", type="string", required=true, description="商品id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
myOrderList
(){
$Order
=
new
Orders
();
$where
[
'user_id'
]
=
$this
->
auth
->
id
;
$where
[
'status'
]
=
'1'
;
$orders
[
'uncomplete'
]
=
$Order
->
orderList
(
$where
);
$where
[
'status'
]
=
'2'
;
$orders
[
'complete'
]
=
$Order
->
orderList
(
$where
);
$this
->
success
(
''
,
$orders
);
}
/**
* @ApiTitle (确认订单)
* @ApiSummary (确认订单)
* @ApiMethod (POST)
* @ApiParams (name="order_id", type="string", required=true, description="订单id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
confirmReceipt
(){
$Order
=
new
Orders
();
$order_id
=
input
(
'order_id'
);
if
(
empty
(
$order_id
)){
$this
->
error
(
'订单id不能为空'
);
}
$where
[
'user_id'
]
=
$this
->
auth
->
id
;
$where
[
'id'
]
=
$order_id
;
$result
=
$Order
->
completeOrder
(
$where
);
if
(
$result
>
0
){
$this
->
success
(
'确认收货成功!'
);
}
$this
->
error
(
'操作失败!'
);
}
/**
* @ApiTitle (删除订单)
* @ApiSummary (删除订单)
* @ApiMethod (POST)
* @ApiParams (name="order_id", type="string", required=true, description="订单id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
deleteOrder
(){
$id
=
input
(
'order_id'
);
$info
=
Orders
::
destroy
(
$id
);
if
(
empty
(
$info
)){
$this
->
error
(
'操作失败!'
);
}
else
{
$this
->
success
(
'操作成功!'
);
}
}
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2019/10/8
* Time: 18:18
*/
namespace
app\api\controller
;
use
app\admin\model\Goods
;
use
app\admin\model\Orders
;
use
app\admin\model\UserAddress
;
use
app\common\controller\Api
;
use
app\common\model\ScoreLog
;
use
think\Db
;
/**
* 积分商城接口
*/
class
Shop
extends
Api
{
protected
$noNeedLogin
=
[
'listMissionType'
];
protected
$noNeedRight
=
[
'*'
];
/**
* @ApiTitle (商品首页)
* @ApiSummary (商品首页)
* @ApiMethod (POST)
* @ApiReturnParams (name="goods_avatar_text", type="string", required=true, description="商品图片")
* @ApiReturnParams (name="good_name", type="string", required=true, description="商品名称")
* @ApiReturnParams (name="price", type="string", required=true, description="商品价格")
* @ApiReturnParams (name="id", type="string", required=true, description="商品id")
* @ApiReturnParams (name="msg", type="string", required=true, description="提示语")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570532904",
"data": {
"total": 1,
"per_page": "10",
"current_page": 1,
"last_page": 1,
"data": [
{
"id": 1,
"goods_avatar": "/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg",
"good_name": "保湿面霜",
"price": 11,
"good_content": "保湿面霜一瓶 <img src=\"http://pyffam7jw.bkt.clouddn.com/uploads/20191008/Fs6sUDk9_iZh5Zhe-xVX8aMeI4Rn.jpg\" alt=\"\" />",
"show_switch": 1,
"createtime": 1570532123,
"weigh": 1,
"deletetime": null,
"goods_avatar_text": "http://pyffam7jw.bkt.clouddn.com/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg"
}
]
}
})
*/
public
function
index
(){
$Goods
=
new
Goods
();
$goods
=
$Goods
->
getIndexGoods
();
$this
->
success
(
''
,
$goods
);
}
/**
* @ApiTitle (商品详情)
* @ApiSummary (商品详情)
* @ApiMethod (POST)
* @ApiReturnParams (name="goods_avatar_text", type="string", required=true, description="商品图片")
* @ApiReturnParams (name="good_name", type="string", required=true, description="商品名称")
* @ApiReturnParams (name="price", type="string", required=true, description="商品价格")
* @ApiReturnParams (name="id", type="string", required=true, description="商品id")
* @ApiReturnParams (name="good_content", type="string", required=true, description="商品详情")
* @ApiReturnParams (name="msg", type="string", required=true, description="提示语")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
"id": 1,
"goods_avatar": "/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg",
"good_name": "保湿面霜",
"price": 11,
"good_content": "保湿面霜一瓶 <img src=\"http://pyffam7jw.bkt.clouddn.com/uploads/20191008/Fs6sUDk9_iZh5Zhe-xVX8aMeI4Rn.jpg\" alt=\"\" />",
"show_switch": 1,
"createtime": 1570532123,
"weigh": 1,
"deletetime": null,
"goods_avatar_text": "http://pyffam7jw.bkt.clouddn.com/uploads/20191008/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg"
}
})
*/
public
function
goodInfo
(){
$id
=
input
(
'id'
);
if
(
empty
(
$id
)){
$this
->
error
(
'缺少必要参数!'
);
}
$Goods
=
new
Goods
();
$info
=
$Goods
::
get
(
$id
)
->
toArray
();
$this
->
success
(
''
,
$info
);
}
/**
* @ApiTitle (获取地址列表)
* @ApiSummary (获取地址列表)
* @ApiMethod (POST)
* @ApiReturnParams (name="id", type="string", required=true, description="地址id")
* @ApiReturnParams (name="user_name", type="string", required=true, description="姓名")
* @ApiReturnParams (name="tel", type="string", required=true, description="电话")
* @ApiReturnParams (name="address", type="string", required=true, description="地址")
* @ApiReturnParams (name="defaultswitch", type="string", required=true, description="是否为默认地址")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
getAddress
(){
$user_id
=
$this
->
auth
->
id
;
$where
[
'user_id'
]
=
$user_id
;
$Address
=
new
UserAddress
();
$list
=
$Address
->
getAddressList
(
$where
);
$this
->
success
(
''
,
$list
);
}
/**
* @ApiTitle (获取默认地址)
* @ApiSummary (获取默认地址)
* @ApiMethod (POST)
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
getDefaultAddress
(){
$user_id
=
$this
->
auth
->
id
;
$where
[
'user_id'
]
=
$user_id
;
$where
[
'defaultswitch'
]
=
1
;
$Address
=
new
UserAddress
();
$list
=
$Address
->
getAddress
(
$where
);
$this
->
success
(
''
,
$list
);
}
/**
* @ApiTitle (创建地址)
* @ApiSummary (创建地址)
* @ApiMethod (POST)
* @ApiParams (name="name", type="string", required=true, description="姓名")
* @ApiParams (name="tel", type="string", required=true, description="电话")
* @ApiParams (name="province", type="string", required=true, description="省市")
* @ApiParams (name="address", type="string", required=true, description="详细地址")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
createAddress
(){
$user_id
=
$this
->
auth
->
id
;
$where
[
'user_id'
]
=
$user_id
;
$Address
=
new
UserAddress
();
$list
=
$Address
->
getAddress
(
$where
);
$insert
[
'user_id'
]
=
$user_id
;
$insert
[
'user_name'
]
=
input
(
'name'
);
$insert
[
'tel'
]
=
input
(
'tel'
);
$insert
[
'province'
]
=
input
(
'province'
);
$insert
[
'address'
]
=
input
(
'address'
);
$insert
[
'createtime'
]
=
time
();
if
(
empty
(
$list
)){
$insert
[
'defaultswitch'
]
=
'1'
;
}
else
{
$insert
[
'defaultswitch'
]
=
'0'
;
}
$result
=
$Address
->
insert
(
$insert
);
if
(
$result
>
0
){
$this
->
success
(
'编辑成功!'
);
}
else
{
$this
->
error
(
'编辑失败!'
);
}
}
/**
* @ApiTitle (获取地址信息)
* @ApiSummary (获取地址信息)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApireturnParams (name="user_name", type="string", required=true, description="用户名")
* @ApireturnParams (name="tel", type="string", required=true, description="电话")
* @ApireturnParams (name="address", type="string", required=true, description="地址")
* @ApireturnParams (name="defaultswitch", type="object", description="是否为默认地址1:是0:不是")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1571030416",
"data": {
"id": 2,
"user_id": 3,
"user_name": "宋国杰",
"tel": "17080088824",
"address": "鑫茂科技园",
"defaultswitch": 0,
"createtime": 1571022797
}
})
*/
public
function
getAddressInfo
(){
$map
[
'id'
]
=
input
(
'address_id'
);
$map
[
'user_id'
]
=
$this
->
auth
->
id
;
$address
=
UserAddress
::
get
(
$map
);
if
(
empty
(
$address
)){
$this
->
error
(
'地址不存在'
);
}
$this
->
success
(
''
,
$address
);
}
/**
* @ApiTitle (编辑地址)
* @ApiSummary (编辑地址)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="user_name", type="string", required=true, description="用户名")
* @ApiParams (name="tel", type="string", required=true, description="电话")
* @ApiParams (name="address", type="string", required=true, description="地址")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
editAddress
(){
$map
[
'id'
]
=
input
(
'address_id'
);
$map
[
'user_id'
]
=
$this
->
auth
->
id
;
$update
[
'user_name'
]
=
input
(
'user_name'
);
$update
[
'tel'
]
=
input
(
'tel'
);
$update
[
'address'
]
=
input
(
'address'
);
$result
=
UserAddress
::
get
(
$map
)
->
save
(
$update
);
if
(
$result
>
0
){
$this
->
success
(
'编辑成功'
);
}
else
{
$this
->
error
(
'编辑失败'
);
}
}
/**
* @ApiTitle (设置默认地址)
* @ApiSummary (设置默认地址)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
setDefaultAddress
(){
$id
=
input
(
'address_id'
);
$user_id
=
$this
->
auth
->
id
;
$map
[
'id'
]
=
$id
;
$map
[
'user_id'
]
=
$user_id
;
$update
[
'defaultswitch'
]
=
1
;
$UserAddress
=
new
UserAddress
();
$map1
[
'user_id'
]
=
$user_id
;
$map1
[
'defaultswitch'
]
=
1
;
$update1
[
'defaultswitch'
]
=
0
;
$address
=
$UserAddress
->
get
(
$map1
);
if
(
!
empty
(
$address
)){
$address
->
save
(
$update1
);
}
$UserAddress
->
get
(
$map
)
->
save
(
$update
);
$this
->
success
(
'设置成功!'
);
}
/**
* @ApiTitle (删除地址)
* @ApiSummary (删除地址)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
deleteAddress
(){
$map
[
'user_id'
]
=
$this
->
auth
->
id
;
$map
[
'id'
]
=
input
(
'address_id'
);
$one
=
UserAddress
::
get
(
$map
);
if
(
empty
(
$one
)){
$this
->
error
(
'地址不存在'
);
}
$result
=
$one
->
delete
();
if
(
$result
>
0
){
$this
->
success
(
'操作成功!'
);
}
else
{
$this
->
error
(
'操作失败!'
);
}
}
/**
* @ApiTitle (提交订单)
* @ApiSummary (提交订单)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="good_id", type="string", required=true, description="商品id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
setOrder
(){
$address_id
=
input
(
'address_id'
);
$good_id
=
input
(
'good_id'
);
if
(
empty
(
$address_id
)
||
empty
(
$good_id
)){
$this
->
error
(
'请选择地址'
);
}
/*查询是有对应地址*/
$address
=
UserAddress
::
get
(
$address_id
);
if
(
empty
(
$address
)){
$this
->
error
(
'地址不存在'
);
}
$address
=
$address
->
toArray
();
$good
=
Goods
::
get
(
$good_id
);
if
(
empty
(
$good
)){
$this
->
error
(
'商品不存在'
);
}
$good
=
$good
->
toArray
();
$user_id
=
$this
->
auth
->
id
;
$user
=
\app\admin\model\User
::
get
(
$user_id
)
->
toArray
();
if
(
$user
[
'score'
]
<
$good
[
'price'
]){
$this
->
error
(
'积分不足!'
);
}
$insert
[
'order_sn'
]
=
cmf_get_order_sn
();
$insert
[
'user_id'
]
=
$user_id
;
$insert
[
'user_name'
]
=
$address
[
'user_name'
];
$insert
[
'tel'
]
=
$address
[
'tel'
];
$insert
[
'address'
]
=
$address
[
'address'
];
$insert
[
'good_id'
]
=
$good_id
;
$insert
[
'price'
]
=
$good
[
'price'
];
$User
=
new
\app\admin\model\User
();
Db
::
startTrans
();
try
{
Orders
::
create
(
$insert
);
$User
->
where
(
'id'
,
$user_id
)
->
setDec
(
'score'
,
$good
[
'price'
]);
$insert_log
[
'user_id'
]
=
$user_id
;
$insert_log
[
'score'
]
=
0
-
$good
[
'price'
];
$insert_log
[
'memo'
]
=
'积分兑换'
;
/*判断是否为现金商品*/
if
(
$good
[
'good_data'
]
==
2
){
/*添加用户现金金额*/
$User
->
where
(
'id'
,
$user_id
)
->
setInc
(
'money'
,
$good
[
'money'
]);
}
ScoreLog
::
create
(
$insert_log
);
// 提交事务
Db
::
commit
();
}
catch
(
\Exception
$e
)
{
// 回滚事务
dump
(
$e
->
getMessage
());
Db
::
rollback
();
$this
->
error
(
'支付失败!'
);
}
$this
->
success
(
'支付成功!'
);
}
/**
* @ApiTitle (我的订单)
* @ApiSummary (我的订单)
* @ApiMethod (POST)
* @ApiParams (name="address_id", type="string", required=true, description="地址id")
* @ApiParams (name="good_id", type="string", required=true, description="商品id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
myOrderList
(){
$Order
=
new
Orders
();
$where
[
'user_id'
]
=
$this
->
auth
->
id
;
$where
[
'status'
]
=
'1'
;
$orders
[
'uncomplete'
]
=
$Order
->
orderList
(
$where
);
$where
[
'status'
]
=
'2'
;
$orders
[
'complete'
]
=
$Order
->
orderList
(
$where
);
$this
->
success
(
''
,
$orders
);
}
/**
* @ApiTitle (确认订单)
* @ApiSummary (确认订单)
* @ApiMethod (POST)
* @ApiParams (name="order_id", type="string", required=true, description="订单id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
confirmReceipt
(){
$Order
=
new
Orders
();
$order_id
=
input
(
'order_id'
);
if
(
empty
(
$order_id
)){
$this
->
error
(
'订单id不能为空'
);
}
$where
[
'user_id'
]
=
$this
->
auth
->
id
;
$where
[
'id'
]
=
$order_id
;
$result
=
$Order
->
completeOrder
(
$where
);
if
(
$result
>
0
){
$this
->
success
(
'确认收货成功!'
);
}
$this
->
error
(
'操作失败!'
);
}
/**
* @ApiTitle (删除订单)
* @ApiSummary (删除订单)
* @ApiMethod (POST)
* @ApiParams (name="order_id", type="string", required=true, description="订单id")
* @ApiParams (name="msg", type="string", required=true, description="提示语")
* @ApiParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "",
"time": "1570533464",
"data": {
}
})
*/
public
function
deleteOrder
(){
$id
=
input
(
'order_id'
);
$info
=
Orders
::
destroy
(
$id
);
if
(
empty
(
$info
)){
$this
->
error
(
'操作失败!'
);
}
else
{
$this
->
success
(
'操作成功!'
);
}
}
}
\ No newline at end of file
...
...
application/api/controller/User.php
查看文件 @
63078ca
...
...
@@ -2,6 +2,7 @@
namespace
app\api\controller
;
use
addons\third\model\Third
;
use
app\admin\model\Area
;
use
app\admin\model\cms\Comment
;
use
app\admin\model\DiaryComment
;
...
...
@@ -261,20 +262,29 @@ class User extends Api
if
(
$money
>
$user
[
'money'
]){
$this
->
error
(
'余额不足!'
);
}
exit
();
$path
=
APP_PATH
.
'cert/'
;
$map
[
'user_id'
]
=
$user_id
;
$openid
=
Third
::
get
(
$map
)
->
openid
;
$options
=
[
'app_id'
=>
'wxf8b3359982b87214'
,
'payment'
=>
[
'merchant_id'
=>
'your-mch-id'
,
'key'
=>
'key-for-signature'
,
'cert_path'
=>
'path/to/your/cert.pem'
,
'key_path'
=>
'path/to/your/key'
,
// ...
'merchant_id'
=>
'1558514191'
,
'key'
=>
'yUKuA7HxasJ3l6m4BaCZrbRhiPapKPAP'
,
'cert_path'
=>
$path
.
'apiclient_cert.pem'
,
'key_path'
=>
$path
.
'apiclient_key.pem'
,
],
];
$Wechat
=
new
Application
(
$options
);
$merchantPay
=
$Wechat
->
merchant_pay
;
$order
=
cmf_get_order_sn
();
$merchantPayData
=
[
'partner_trade_no'
=>
str_random
(
16
),
//随机字符串作为订单号,跟红包和支付一个概念。
'openid'
=>
$this
->
auth
->
openid
,
//收款人的openid
'partner_trade_no'
=>
$order
,
//随机字符串作为订单号,跟红包和支付一个概念。
'openid'
=>
$openid
,
//收款人的openid
'check_name'
=>
'NO_CHECK'
,
//文档中有三种校验实名的方法 NO_CHECK OPTION_CHECK FORCE_CHECK
//'re_user_name'=>'张三', //OPTION_CHECK FORCE_CHECK 校验实名的时候必须提交
'amount'
=>
$money
*
100
,
//单位为分
...
...
@@ -282,6 +292,16 @@ class User extends Api
// 'spbill_create_ip' => '192.168.0.1', //发起交易的IP地址
];
$result
=
$merchantPay
->
send
(
$merchantPayData
);
$User
=
new
\app\admin\model\User
();
if
(
$result
[
'result_code'
]
==
'SUCCESS'
){
/*扣除对应金额*/
/*记入现金log*/
$User
->
where
(
'id'
,
$user_id
)
->
setDec
(
'money'
,
$money
);
$this
->
success
(
'付款成功!'
);
}
else
{
$this
->
error
(
$result
[
'err_code_des'
]);
}
}
/**
* @ApiTitle (获取用户信息)
...
...
application/extra/site.php
查看文件 @
63078ca
...
...
@@ -2,7 +2,7 @@
return
array
(
'name'
=>
'微养生1'
,
'beian'
=>
''
,
'beian'
=>
'
浙ICP备19028672号-1
'
,
'cdnurl'
=>
''
,
'version'
=>
'1.0.1'
,
'timezone'
=>
'Asia/Shanghai'
,
...
...
@@ -35,8 +35,9 @@ return array (
'mail_smtp_pass'
=>
'password'
,
'mail_verify_type'
=>
'2'
,
'mail_from'
=>
'10000@qq.com'
,
'ratio'
=>
'10'
,
'early_time'
=>
'40'
,
'ratio'
=>
'10000'
,
'early_time'
=>
'30'
,
'range'
=>
'1000'
,
'message'
=>
'挑战任务成功将获得相当于加油金10倍的挑战奖金。奖金通过积分发放,可直接兑换等价值的奖金,并提现至微信钱包。'
,
'late_time'
=>
'15'
,
);
\ No newline at end of file
...
...
public/assets/js/backend/goods.js
查看文件 @
63078ca
...
...
@@ -31,6 +31,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{
field
:
'show_switch'
,
title
:
__
(
'Show_switch'
),
searchList
:
{
"1"
:
__
(
'Yes'
),
"0"
:
__
(
'No'
)},
formatter
:
Table
.
api
.
formatter
.
toggle
},
{
field
:
'createtime'
,
title
:
__
(
'Createtime'
),
operate
:
'RANGE'
,
addclass
:
'datetimerange'
,
formatter
:
Table
.
api
.
formatter
.
datetime
},
{
field
:
'weigh'
,
title
:
__
(
'Weigh'
)},
{
field
:
'good_data'
,
title
:
__
(
'Good_data'
),
searchList
:
{
"1"
:
__
(
'Good_data 1'
),
"2"
:
__
(
'Good_data 2'
)},
formatter
:
Table
.
api
.
formatter
.
normal
},
{
field
:
'money'
,
title
:
__
(
'Money'
),
operate
:
'BETWEEN'
},
{
field
:
'operate'
,
title
:
__
(
'Operate'
),
table
:
table
,
events
:
Table
.
api
.
events
.
operate
,
formatter
:
Table
.
api
.
formatter
.
operate
}
]
]
...
...
请
注册
或
登录
后发表评论