Blogger Information
Blog 38
fans 0
comment 0
visits 18524
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
VUE:购物车页面:全选按钮 & 代码练习
Blackeye
Original
1364 people have browsed it

index.vue

  1. <template>
  2. <div>
  3. <div class="fui-content" style="height:854px;background:#f3f3f3;">
  4. <div class="content-empty" v-if="shop_show==0">
  5. <img class="img" src="http://d.vsd.cc/addons/ewei_shopv2/static/images/nogoods.png"/>
  6. <div class="title">您的购物车中没有商品哦!</div>
  7. <button style='width:50%;margin-top:1rem;'>去看看商品吧</button>
  8. </div>
  9. <div v-if="shop_show==1" style="padding-bottom: 64px;">
  10. <div class="fui-list goods-item align-start" v-for="(item,index,key) in shop" :key="key">
  11. <div class="fui-list-media">
  12. <input name="sid" type="checkbox" :value="item.id" @click="checkOne" v-model="item.check"/>
  13. </div>
  14. <div class="fui-list-media image-media">
  15. <img class="img" :src="item.shop.img_s"/>
  16. </div>
  17. <div class="fui-list-inner">
  18. <div class="subtitle">{{item.shop.title}}</div>
  19. <div class="price" style='margin-top:30px;'>
  20. <span class="bigprice text-danger">
  21. <span>¥</span>
  22. <span>{{item.shop.price}}</span>
  23. </span>
  24. <div class="fui-number small">
  25. <button class="minus" @click="jian(item.id)">-</button>
  26. <input class="num" disabled="true" :value="item.num" />
  27. <button class="plus" @click="jia(item.id)">+</button>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="fui-footer">
  35. <div class="fui-footer-list">
  36. <div class="editmode" style="font-size: 0.7rem;color: #666;">
  37. <input name="Fruit" type="checkbox" value="" v-model="is_check" @click="checkall"/>全选
  38. </div>
  39. <div class="fui-footer-inner">
  40. <div class="footer-subtitle">合计:<span class="text-danger size0-75rem"> ¥{{price}}</span></div>
  41. </div>
  42. <div class="fui-list-angle">
  43. <button class="btn" @click="order()">结算({{number}})</button>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import Header from '../../components/Header.vue';
  51. import { reactive, toRefs } from "vue";
  52. import { useRoute,useRouter } from "vue-router";
  53. import { CartIndex,EidtCart } from "../../network/index.js";
  54. export default({
  55. setup() {
  56. const token = window.localStorage.getItem('token');
  57. const route = useRoute();
  58. const router = useRouter();
  59. if(!token){
  60. alert('请您先登录');
  61. router.push({
  62. path: "/login"
  63. });
  64. }
  65. const order = ()=>{
  66. let ids = '';
  67. for(let i=0;i<data.shop.length;i++){
  68. ids += data.shop[i].id + ';';
  69. }
  70. router.push("/cart_order?t=1&id="+ids);
  71. }
  72. const data = reactive({
  73. shop : [],
  74. number : 0,
  75. price : 0,
  76. is_check : false,
  77. check_help: 0
  78. })
  79. CartIndex({token:token}).then( (e)=>{
  80. for(let i=0;i<e.data.length;i++){
  81. e.data[i].check = false;
  82. }
  83. data.shop = e.data;
  84. } )
  85. const checkOne = (e)=>{
  86. for(let i=0;i<data.shop.length;i++){
  87. if(data.shop[i].id == e.target.value){
  88. if(e.target.checked == true){
  89. data.number += data.shop[i].num;
  90. data.price += data.shop[i].num * data.shop[i].shop.price;
  91. data.check_help++;
  92. }else{
  93. data.number -= data.shop[i].num;
  94. data.price -= data.shop[i].num * data.shop[i].shop.price;
  95. data.check_help--;
  96. }
  97. }
  98. }
  99. if(data.check_help == data.shop.length){
  100. checkall();
  101. }else{
  102. data.is_check = false;
  103. }
  104. }
  105. const jian = (id)=>{
  106. for(let i=0;i<data.shop.length;i++){
  107. if(data.shop[i].num > 1){
  108. if(data.shop[i].id == id){
  109. data.shop[i].num --;
  110. EidtCart({token:token,id:id,num:data.shop[i].num}).then( ()=>{
  111. } )
  112. if(data.shop[i].check == true){
  113. data.number -= 1;
  114. data.price -= data.shop[i].shop.price;
  115. }
  116. }
  117. }else{
  118. if(window.confirm('确定删除吗?')){
  119. alert('确定');
  120. return true;
  121. }
  122. }
  123. }
  124. }
  125. const jia = (id)=>{
  126. for(let i=0;i<data.shop.length;i++){
  127. if(data.shop[i].id == id){
  128. data.shop[i].num ++;
  129. EidtCart({token:token,id:id,num:data.shop[i].num}).then( ()=>{
  130. } )
  131. if(data.shop[i].check == true){
  132. data.number += 1;
  133. data.price += data.shop[i].shop.price;
  134. }
  135. }
  136. }
  137. }
  138. const checkall = ()=>{
  139. data.is_check = !data.is_check;
  140. let tmp_number = 0;
  141. let tmp_price = 0;
  142. for(let i=0;i<data.shop.length;i++){
  143. data.shop[i].check = data.is_check;
  144. tmp_number += data.shop[i].num;
  145. tmp_price += data.shop[i].num * data.shop[i].shop.price;
  146. }
  147. if(data.is_check == true){
  148. data.number = tmp_number;
  149. data.price = tmp_price;
  150. data.check_help = 2;
  151. }else{
  152. data.number = 0;
  153. data.price = 0;
  154. data.check_help = 0;
  155. }
  156. }
  157. return{
  158. order,
  159. shop_show:1,
  160. ...toRefs(data),
  161. checkOne,
  162. jian,
  163. jia,
  164. checkall
  165. }
  166. },
  167. })
  168. </script>
  169. <style scoped>
  170. .fui-content {
  171. position: absolute;
  172. right: 0;
  173. left: 0;
  174. overflow: auto;
  175. padding-bottom: 2.2rem;
  176. }
  177. .content-empty {
  178. position: relative;
  179. text-align: center;
  180. margin-top: 3rem;
  181. color: #ccc;
  182. -webkit-box-align: center;
  183. }
  184. .img{
  185. width: 198rpx;
  186. margin-bottom: .5rem;
  187. }
  188. .title{
  189. color: #999;
  190. font-size: .75rem
  191. }
  192. .url{
  193. border-radius: 100px;
  194. height: 1.9rem;
  195. line-height:1.9rem;
  196. width:7rem;
  197. font-size:0.75rem;
  198. }
  199. /* 有商品 */
  200. .fui-list {
  201. position: relative;
  202. display: flex;
  203. transition-duration: 300ms;
  204. align-items: center;
  205. overflow: hidden;
  206. -webkit-box-align: start;
  207. padding: 0.65rem 0.6rem;
  208. margin-top: 0.5rem;
  209. background-color: #fff;
  210. }
  211. .fui-list-media {
  212. display: flex;
  213. flex-shrink: 0;
  214. -webkit-box-lines: single;
  215. flex-wrap: nowrap;
  216. box-sizing: border-box;
  217. -webkit-box-align: center;
  218. align-items: center;
  219. margin-right: 0.6rem;
  220. color: #aaa;
  221. position: relative;
  222. }
  223. .img{
  224. width: 86px;
  225. height: 86px;
  226. }
  227. image-media {
  228. margin-left: 1rem;
  229. align-self: center;
  230. }
  231. .fui-list-inner {
  232. position: relative;
  233. width: 100%;
  234. overflow: hidden;
  235. box-sizing: border-box;
  236. -webkit-box-flex: 1;
  237. flex: 1;
  238. justify-content: space-between;
  239. flex-direction: column;
  240. -webkit-box-pack: justify;
  241. min-height: 4.6rem;
  242. align-self: center;
  243. }
  244. .subtitle{
  245. align-items: center;
  246. position: relative;
  247. font-size: 0.7rem;
  248. margin-top: 0.2rem;
  249. overflow: hidden;
  250. text-overflow: ellipsis;
  251. display: -webkit-box;
  252. -webkit-line-clamp: 2;
  253. -webkit-box-orient: vertical;
  254. white-space: normal;
  255. color: #000;
  256. }
  257. .price {
  258. display: flex;
  259. -webkit-box-pack: justify;
  260. justify-content: space-between;
  261. height: 1.2rem;
  262. font-size: 0.65rem;
  263. color: #000;
  264. }
  265. .bigprice {
  266. font-size: 0.75rem;
  267. }
  268. .text-danger {
  269. color: #ff5555;
  270. }
  271. .fui-number {
  272. backface-visibility: hidden;
  273. box-sizing: border-box;
  274. position: relative;
  275. display: flex;
  276. font-size: 0.8rem;
  277. -webkit-box-pack: justify;
  278. justify-content: space-between;
  279. margin: 0;
  280. }
  281. .small {
  282. height: 1.1rem;
  283. width: 79px;
  284. line-height: 1.2rem;
  285. }
  286. .minus {
  287. height: inherit;
  288. font-weight: bold;
  289. position: relative;
  290. text-align: center;
  291. z-index: 1;
  292. font-size: 0.65rem;
  293. color: #666;
  294. background: #fff;
  295. width: 1.1rem;
  296. line-height: 1.1rem;
  297. }
  298. .num {
  299. -webkit-box-flex: 1;
  300. flex: 1;
  301. overflow: hidden;
  302. line-height: inherit;
  303. color: #666;
  304. text-align: center;
  305. border: 0;
  306. font-size: 0.7rem;
  307. }
  308. .plus {
  309. height: inherit;
  310. font-weight: bold;
  311. position: relative;
  312. text-align: center;
  313. z-index: 1;
  314. font-size: 0.65rem;
  315. color: #666;
  316. background: #fff;
  317. width: 1.1rem;
  318. line-height: 1.1rem;
  319. }
  320. /* 底部按钮 */
  321. .fui-footer {
  322. position: fixed;
  323. width: 100%;
  324. height: 2.45rem;
  325. background: #fff;
  326. box-shadow: 0 0 4px rgba(0,0,0,0.1);
  327. -webkit-box-shadow: 0 0 4px rgba(0,0,0,0.1);
  328. -moz-box-shadow: 0 0 4px rgba(0,0,0,0.1);
  329. z-index: 2;
  330. padding: 0 0 90px 0;
  331. margin: 0;
  332. bottom: 0;
  333. }
  334. .fui-footer-list{
  335. align-items: center;
  336. overflow: hidden;
  337. transition-duration: 300ms;
  338. -webkit-box-align: center;
  339. display: flex;
  340. position: relative;
  341. justify-content: space-between;padding: 0 0 0 .6rem;
  342. height: 2.45rem;
  343. -webkit-box-pack: justify;
  344. }
  345. .editmode{
  346. align-items: center;
  347. margin-right: .6rem;
  348. color: #aaa;
  349. position: relative;
  350. flex-wrap: nowrap;
  351. box-sizing: border-box;
  352. -webkit-box-align: center;
  353. flex-shrink: 0;
  354. -webkit-box-lines: single;
  355. }
  356. .fui-footer-inner{
  357. box-sizing: border-box;
  358. -webkit-tap-highlight-color: transparent;
  359. margin: 0;
  360. padding: 0;
  361. position: relative;
  362. font-size: .7rem;
  363. color: #666;
  364. padding-left: 1.2rem;
  365. vertical-align: middle;
  366. }
  367. .footer-subtitle{
  368. -webkit-line-clamp: 1;
  369. -webkit-box-orient: vertical;
  370. overflow: hidden;
  371. text-overflow: ellipsis;
  372. position: relative;
  373. color: #000;
  374. font-size: .7rem;
  375. margin-top: .2rem;
  376. display: flex;
  377. align-items: flex-end;
  378. padding: 0;
  379. justify-content: flex-end;
  380. -webkit-box-pack: end;
  381. }
  382. .fui-list-angle{
  383. position: relative;
  384. vertical-align: middle;
  385. padding: 0;
  386. display: flex;
  387. margin: 0;
  388. }
  389. .btn{
  390. background: #ff5555;
  391. border: 0;
  392. padding: 0;
  393. margin: 0;
  394. border-radius: 0;
  395. height: 100%;
  396. line-height: 2.45rem;
  397. font-size: .7rem;
  398. color: #fff;
  399. margin-left: .05rem;
  400. width: 5rem;
  401. }
  402. </style>

Order.vue

  1. <template>
  2. <div>
  3. <Header :title="title"></Header>
  4. <div class="fui-page order-create-page fui-page-current" style="height:100%;margin-top:40px;">
  5. <div class='fui-content navbar'>
  6. <!-- 地址 -->
  7. <div class="fui-list-group" @click="is_a()">
  8. <div class="fui-list">
  9. <div class="fui-list-inner">
  10. <div class="title">
  11. 收货人:
  12. <span class="realname">{{address_se.name}}</span>
  13. <span class="mobile">{{address_se.phone}}</span>
  14. </div>
  15. <div class="title">
  16. <span class="address">{{address_se.address}}</span>
  17. </div>
  18. </div>
  19. <div class="address_img">
  20. <img src="@/assets/images/right.png" />
  21. </div>
  22. </div>
  23. </div>
  24. <div v-if="is_address">
  25. <div class="ant-modal-mask"></div>
  26. <div class="fui-list-group" style="position:fixed;top:30%;z-index:1000;position: fixed;inset: 0;overflow: auto;outline: 0;">
  27. <div class="fui-list" @click="is_a_se(index)" v-for="(item,index,key) in address" :key="key">
  28. <div class="fui-list-inner">
  29. <div class="title">
  30. 收货人:
  31. <span class="realname">{{item.name}}</span>
  32. <span class="mobile">{{item.phone}}</span>
  33. </div>
  34. <div class="title">
  35. <span class="address">{{item.address}}</span>
  36. </div>
  37. </div>
  38. </div>
  39. <div style="text-align:center;font-size:20px;margin-top:20px;" @click="is_a()">X</div>
  40. </div>
  41. </div>
  42. <!-- 地址end -->
  43. <!-- 商品 -->
  44. <div class='fui-shop'>
  45. <div class='fui-shop-list' v-for="(item,index,key) in shop" :key="key">
  46. <div class="fui-shop-list-media">
  47. <img class="img" :src="item.img_s"/>
  48. </div>
  49. <div class="shops" style='folat:left;width:250px;'>
  50. <div class="subtitle">{{item.title}}</div>
  51. </div>
  52. <div class="fui-list-angle">
  53. <span style="font-size: 0.65rem;color: #000"><span class="marketprice">{{item.price}}</span></span>
  54. <div style='color: #999;'>x{{item.number}}</div>
  55. </div>
  56. </div>
  57. </div>
  58. <!-- 商品end -->
  59. <!-- 买家留言 -->
  60. <div class="fui-cell-group">
  61. <div class="fui-cell fui-cell-textarea">
  62. <div class="fui-cell-label">
  63. 买家留言
  64. </div>
  65. <div class="fui-cell-info">
  66. <textarea class='textarea' rows="2" placeholder="50字以内(选填)"></textarea>
  67. </div>
  68. </div>
  69. </div>
  70. <!-- 买家留言end -->
  71. <!-- 支付按钮 -->
  72. <div class="fui-navbar">
  73. <div class="nav-item total">
  74. 需付:<span class="text-danger size0-75rem">¥ {{total}}</span>
  75. <button class="nav-item btn btn-danger buybtn" style="width:200px;margin-left:10px;" @click="order()">确定订单</button>
  76. </div>
  77. </div>
  78. <!-- 支付按钮end -->
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import { reactive, toRefs } from "vue";
  85. import Header from '../../components/Header.vue';
  86. import { useRoute,useRouter } from "vue-router";
  87. import { ShopOne,AddOrder } from "../../network/index.js";
  88. export default({
  89. components: {
  90. Header
  91. },
  92. setup() {
  93. const token = window.localStorage.getItem('token');
  94. const route = useRoute();
  95. const router = useRouter();
  96. if(!token){
  97. alert('请您先登录');
  98. router.push({
  99. path: "/login"
  100. });
  101. }
  102. // 2022年5月18日作业:
  103. // 1、课上代码练习:商品详情页,登录页,下单页
  104. // 2、提前复习:订单支付页,展示数据,支付成功(不需要支付宝和微信)
  105. const order = ()=>{
  106. AddOrder({token:token,id:route.query.id,address:data.address_se.id}).then( (e)=>{
  107. alert(e.msg);
  108. if(e.code == 0){
  109. router.push({
  110. path: "/cart_pay",
  111. query: { id: e.data }
  112. });
  113. }
  114. } )
  115. }
  116. const data = reactive({
  117. shop : [],
  118. address : [
  119. {
  120. id : 1,
  121. name : "欧阳克",
  122. phone : "18811112222",
  123. address : "安徽省合肥市政务区银泰城609"
  124. },
  125. {
  126. id : 2,
  127. name : "朱天蓬",
  128. phone : "18811113333",
  129. address : "安徽省合肥市政务区银泰城609"
  130. },
  131. {
  132. id : 3,
  133. name : "灭绝师太",
  134. phone : "18811114444",
  135. address : "安徽省合肥市政务区银泰城609"
  136. }
  137. ],
  138. is_address : false,
  139. address_se : [],
  140. total:0
  141. });
  142. const is_a = ()=>{
  143. if(data.is_address == true){
  144. data.is_address = false;
  145. }else{
  146. data.is_address = true;
  147. }
  148. }
  149. const is_a_se = (e)=>{
  150. data.is_address = false;
  151. data.address_se = data.address[e];
  152. }
  153. ShopOne({id:route.query.id,token:token,t:route.query.t}).then( (e)=>{
  154. data.address = e.data.address;
  155. data.shop = e.data.shop;
  156. data.total = e.data.total;
  157. data.address_se = e.data.address[0];
  158. } )
  159. return {
  160. title:"下单",
  161. order,
  162. ...toRefs(data),
  163. is_a,
  164. is_a_se
  165. };
  166. }
  167. })
  168. </script>
  169. <style scoped>
  170. .fui-page {
  171. position: absolute;
  172. left: 0;
  173. top: 0;
  174. width: 100%;
  175. height: 100%;
  176. background: #f3f3f3;
  177. box-sizing: border-box;
  178. display: none;
  179. }
  180. .order-create-page {
  181. margin: 0;
  182. bottom: 2rem;
  183. padding-bottom: 2rem;
  184. display: block;
  185. overflow: hidden;
  186. }
  187. .fui-content {
  188. position: absolute;
  189. top: 0;
  190. right: 0;
  191. bottom: 0;
  192. left: 0;
  193. overflow: auto;
  194. -webkit-overflow-scrolling: touch;
  195. }
  196. .fui-content.navbar {
  197. bottom: 2.5rem;
  198. padding-bottom: 2.2rem;
  199. }
  200. /* 地址 */
  201. .fui-list-group {
  202. background-color: #fff;
  203. position: relative;
  204. margin: 0 0 0.5rem;
  205. }
  206. .fui-list {
  207. position: relative;
  208. display: flex;
  209. padding: .4rem .6rem;
  210. transition-duration: 300ms;
  211. align-items: center;
  212. overflow: hidden;
  213. padding-top: 0.8rem;
  214. padding-bottom: 0.83rem;
  215. }
  216. .fui-list-inner {
  217. position: relative;
  218. width: 100%;
  219. overflow: hidden;
  220. box-sizing: border-box;
  221. -ms-flex: 1;
  222. flex: 1;
  223. display: block;
  224. align-self: flex-start;
  225. }
  226. .fui-list-inner .text {
  227. position: relative;
  228. font-size: .7rem;
  229. color: #000;
  230. text-align: center;
  231. }
  232. .fui-list-inner .title {
  233. position: relative;
  234. white-space: nowrap;
  235. text-overflow: ellipsis;
  236. overflow: hidden;
  237. display: flex;
  238. color: #000;
  239. font-size: .7rem;
  240. line-height: 1.2rem;
  241. height: 1.2rem;
  242. }
  243. .realname {
  244. display: inline-block;
  245. max-width: 9rem;
  246. white-space: nowrap;
  247. text-overflow: ellipsis;
  248. overflow: hidden;
  249. padding-right: 1.2rem;
  250. }
  251. .mobile {
  252. display: inline-block;
  253. overflow: hidden;
  254. }
  255. .address{
  256. overflow: hidden;
  257. text-overflow: ellipsis;
  258. font-size: 0.65rem;
  259. color: #666;
  260. }
  261. .address_img{
  262. float: right;
  263. display: block;
  264. }
  265. /* 地址end */
  266. /* 商品 */
  267. .fui-shop {
  268. background-color: #fff;
  269. position: relative;
  270. margin-top: 0.5rem;
  271. }
  272. .fui-shop-list {
  273. align-items: center;
  274. overflow: hidden;
  275. transition-duration: 300ms;
  276. display: flex;
  277. padding: 0.4rem 0.6rem;
  278. position: relative;
  279. -webkit-box-align: start;
  280. }
  281. .fui-shop-list-media{
  282. display: flex;
  283. align-items: center;
  284. margin-right: 0.6rem;
  285. color: #aaa;
  286. position: relative;
  287. flex-wrap: nowrap;
  288. box-sizing: border-box;
  289. -webkit-box-align: center;
  290. flex-shrink: 0;
  291. -webkit-box-lines: single;
  292. }
  293. .img{
  294. width: 4rem;
  295. height: 4rem;
  296. }
  297. .shops {
  298. height: 3.5rem;
  299. align-self: center;
  300. justify-content: space-between;
  301. flex-direction: column;
  302. -webkit-box-pack: justify;
  303. display: flex;
  304. }
  305. .subtitle {
  306. color: #000;
  307. font-size: 0.7rem;
  308. overflow: hidden;
  309. text-overflow: ellipsis;
  310. display: -webkit-box;
  311. -webkit-line-clamp: 2;
  312. -webkit-box-orient: vertical;
  313. white-space: normal;
  314. }
  315. .fui-list-angle {
  316. text-align: right;
  317. font-size: 0.7rem;
  318. color: #666;
  319. margin-right: 0.1rem;
  320. right: 20px;
  321. position:absolute;
  322. vertical-align: middle;
  323. height: 3.5rem;
  324. align-self: center;
  325. width: 3.5rem
  326. }
  327. /* 买家留言 */
  328. .fui-cell-group {
  329. margin-top: 0.5rem;
  330. background-color: #fff;
  331. line-height: 1.4;
  332. font-size: 0.8rem;
  333. overflow: hidden;
  334. position: relative;
  335. display: block;
  336. }
  337. .fui-cell-group .fui-cell {
  338. position: relative;
  339. padding: 0.75rem 0.6rem 0.65rem;
  340. display: flex;
  341. transition-duration: 300ms;
  342. line-height: 1.2;
  343. height: 2.5rem;
  344. align-items: flex-start;
  345. }
  346. .fui-cell-group .fui-cell .fui-cell-label {
  347. position: relative;
  348. display: block;
  349. width: 3.85rem;
  350. font-size: 0.7rem;
  351. color: #666;
  352. margin: 0.15rem 0 0 0;
  353. }
  354. .fui-cell-group .fui-cell .fui-cell-info {
  355. -webkit-box-flex: 1;
  356. flex: 1;
  357. white-space: nowrap;
  358. text-overflow: ellipsis;
  359. overflow: hidden;
  360. font-size: 0.7rem;
  361. color: #000;
  362. }
  363. .textarea {
  364. width: 100%;
  365. background: transparent;
  366. border: none;
  367. resize: none;
  368. font-size: 0.7rem;
  369. font-family: "Helvetica Neue", Helvetica, sans-serif;
  370. }
  371. /* 支付按钮 */
  372. .fui-navbar{
  373. position: fixed;
  374. width: 100%;
  375. bottom: 0;
  376. height: 2.45rem;
  377. background: #fff;
  378. z-index: 2;
  379. }
  380. .fui-navbar .nav-item {
  381. position: relative;
  382. display: table-cell;
  383. height: 2.45rem;
  384. text-align: center;
  385. vertical-align: middle;
  386. width: 1%;
  387. color: #999;
  388. }
  389. .total {
  390. padding-left: 0;
  391. padding-right: 0.5rem;
  392. font-size: 0.7rem;
  393. height: 2.45rem;
  394. }
  395. .order-create-page .buybtn {
  396. border: none;
  397. font-size: 0.7rem;
  398. color: #fff;
  399. border-radius: 0;
  400. width: 0.2%;
  401. }
  402. .fui-navbar .nav-item.btn {
  403. color: #fff;
  404. border-radius: 0;
  405. }
  406. .btn.btn-danger {
  407. background: #ff5555;
  408. color: #fff;
  409. border: 1px solid #ff5555;
  410. }
  411. </style>

Pay.vue

  1. <template>
  2. <div>
  3. <Header :title="title"></Header>
  4. <div class="fui-page order-create-page fui-page-current" style="height:100%;margin-top:40px;">
  5. <div class='fui-content navbar'>
  6. <div class="totals">
  7. <span>订单号</span>
  8. <div class="num">{{order.oid}}</div>
  9. </div>
  10. <div class="totals">
  11. <span>总计</span>
  12. <div class="num"><span class="iconfont icon-renminbi1688"></span>{{order.money}}</div>
  13. </div>
  14. <div class="pay">
  15. <div class="channel">
  16. <div class="left">
  17. <span class="wx iconfont icon-weixin"></span>
  18. <span>微信支付</span>
  19. </div>
  20. <div class="right">
  21. <label>
  22. <input type="radio" value="1" name="pay_type" checked="checked" v-model="is_pay">
  23. </label>
  24. </div>
  25. </div>
  26. <div class="channel">
  27. <div class="left">
  28. <span class="zfb iconfont icon-zhifubaozhifu"></span>
  29. <span>支付宝</span>
  30. </div>
  31. <div class="right">
  32. <label>
  33. <input type="radio" value="2" name="pay_type" v-model="is_pay">
  34. </label>
  35. </div>
  36. </div>
  37. </div>
  38. <!-- 支付按钮 -->
  39. <div class="fui-navbar">
  40. <div class="nav-item total">
  41. 需付:<span class="text-danger size0-75rem">¥ {{order.money}}</span>
  42. <button class="nav-item btn btn-danger buybtn" style="width:200px;margin-left:10px;" @click="go_order()">确定支付</button>
  43. </div>
  44. </div>
  45. <!-- 支付按钮end -->
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import Header from '../../components/Header.vue';
  52. import { reactive, toRefs } from "vue";
  53. import { useRoute,useRouter } from "vue-router";
  54. import { PayOrder, Pay } from "../../network/index.js";
  55. export default {
  56. components:{
  57. Header
  58. },
  59. setup() {
  60. const token = window.localStorage.getItem('token');
  61. const route = useRoute();
  62. const router = useRouter();
  63. if(!token){
  64. alert('请您先登录');
  65. router.push({
  66. path: "/login"
  67. });
  68. }
  69. const data = reactive({
  70. order : [],
  71. is_pay : 1
  72. })
  73. PayOrder({token:token,id:route.query.id}).then( (e)=>{
  74. console.log(e);
  75. data.order = e.data;
  76. })
  77. const go_order = ()=>{
  78. Pay({token:token,id:route.query.id,is_pay:data.is_pay}).then( ()=>{
  79. router.push({
  80. path: "/my_order_details?id="+route.query.id
  81. });
  82. } )
  83. }
  84. return {
  85. title : '购买课程',
  86. ...toRefs(data),
  87. go_order
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped>
  93. .fui-page {
  94. position: absolute;
  95. left: 0;
  96. top: 0;
  97. width: 100%;
  98. height: 100%;
  99. background: #f3f3f3;
  100. box-sizing: border-box;
  101. display: none;
  102. }
  103. .order-create-page {
  104. margin: 0;
  105. bottom: 2rem;
  106. padding-bottom: 2rem;
  107. display: block;
  108. overflow: hidden;
  109. }
  110. .fui-content {
  111. position: absolute;
  112. top: 0;
  113. right: 0;
  114. bottom: 0;
  115. left: 0;
  116. overflow: auto;
  117. -webkit-overflow-scrolling: touch;
  118. }
  119. .fui-content.navbar {
  120. bottom: 2.5rem;
  121. padding-bottom: 2.2rem;
  122. }
  123. /* 支付按钮 */
  124. .fui-navbar{
  125. position: fixed;
  126. width: 100%;
  127. bottom: 0;
  128. height: 2.45rem;
  129. background: #fff;
  130. z-index: 2;
  131. }
  132. .fui-navbar .nav-item {
  133. position: relative;
  134. display: table-cell;
  135. height: 2.45rem;
  136. text-align: center;
  137. vertical-align: middle;
  138. width: 1%;
  139. color: #999;
  140. }
  141. .total {
  142. padding-left: 0;
  143. padding-right: 0.5rem;
  144. font-size: 0.7rem;
  145. height: 2.45rem;
  146. }
  147. .order-create-page .buybtn {
  148. border: none;
  149. font-size: 0.7rem;
  150. color: #fff;
  151. border-radius: 0;
  152. width: 0.2%;
  153. }
  154. .fui-navbar .nav-item.btn {
  155. color: #fff;
  156. border-radius: 0;
  157. }
  158. .btn.btn-danger {
  159. background: #ff5555;
  160. color: #fff;
  161. border: 1px solid #ff5555;
  162. }
  163. .totals {
  164. background-color: #fff;
  165. padding: 20px;
  166. height: 60px;
  167. display: flex;
  168. place-content: space-between;
  169. color: gray;
  170. font-size: large;
  171. margin: 20px 0;
  172. }
  173. .pay {
  174. background-color: #fff;
  175. padding: 20px;
  176. height: 140px;
  177. margin: 20px 0;
  178. color: gray;
  179. font-size: 12px;
  180. }
  181. .pay .channel {
  182. padding: 10px;
  183. display: flex;
  184. place-items: center;
  185. place-content: space-between;
  186. }
  187. .pay .channel .left {
  188. font-size: larger;
  189. display: flex;
  190. place-items: center;
  191. }
  192. .pay .channel .left .wx {
  193. color: forestgreen;
  194. }
  195. .pay .channel .left .zfb {
  196. color: deepskyblue;
  197. }
  198. .pay .channel .left .iconfont {
  199. font-size: xx-large;
  200. margin-right: 10px;
  201. }
  202. .pay .channel + * {
  203. border-top: 1px solid lightgray;
  204. }
  205. </style>

Details.vue

  1. <template>
  2. <div>
  3. <Header :title="title" :is_img="1"></Header>
  4. <div class="rele-wrap">
  5. <div class="has-bottom">
  6. <swiper :modules="modules" :loop="true" :pagination="swiper_options.pagination" :autoplay="swiper_options.autoplay" class="swiper">
  7. <swiper-slide v-for="(item,index,key) in shop.img_s" :key="key">
  8. <img :src="item" alt="" class="active" />
  9. </swiper-slide>
  10. </swiper>
  11. <div class="idle-panel">
  12. <div class="p1">{{shop.title}}</div>
  13. <div class="p2"><text class="span">{{shop.price}}元</text></div>
  14. </div>
  15. <div class="sale-panel">
  16. <div class="tit">商品详情</div>
  17. <div class="all open">
  18. <img :src="item" v-for="(item,index,key) in shop.info_s" :key="key" />
  19. </div>
  20. </div>
  21. </div>
  22. <div class="fui-navbar bottom-buttons">
  23. <button class="btn btn_left" @click="add()">加入购物车</button>
  24. <button class="btn btn_right" @click="go_url()">立即购买</button>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import { reactive, toRefs } from "vue";
  31. import { useRoute,useRouter } from "vue-router";
  32. import Header from '../../components/Header.vue';
  33. import { GoodsDetails,AddCart } from "../../network/index.js";
  34. import SwiperCore,{ Pagination,Autoplay} from "swiper";
  35. import { Swiper, SwiperSlide } from "swiper/vue/swiper-vue.js";
  36. import "swiper/swiper.min.css";
  37. import "swiper/modules/pagination/pagination.min.css";
  38. SwiperCore.use([Autoplay,Pagination]);
  39. export default {
  40. components: {
  41. Swiper,
  42. SwiperSlide,
  43. Header
  44. },
  45. setup() {
  46. const swiper_options = new reactive({
  47. pagination: {
  48. clickable: true,
  49. },
  50. autoplay: {
  51. disableOnInteraction: false, // 鼠标滑动后继续自动播放
  52. delay: 2000, //2秒切换一次
  53. pauseOnMouseEnter: true,
  54. },
  55. speed: 500, //切换过渡速度
  56. })
  57. const data = reactive({
  58. shop : [],
  59. token : 0
  60. })
  61. data.token = window.localStorage.getItem('token');
  62. const route = useRoute();
  63. const router = useRouter();
  64. const go_url = ()=>{
  65. if(data.token == 0){
  66. router.push('/login');
  67. return false;
  68. }
  69. router.push("/cart_order?t=0&id="+route.query.id);
  70. }
  71. GoodsDetails({id:route.query.id}).then( (e)=>{
  72. data.shop = e.data;
  73. } )
  74. const add = ()=>{
  75. // 判断token是否为0,0未登录
  76. if(data.token == 0){
  77. router.push('/login');
  78. return false;
  79. }
  80. AddCart({sid:route.query.id,uid:1}).then( (e)=>{
  81. console.log(e);
  82. alert(e.msg);
  83. } )
  84. }
  85. return {
  86. swiper_options,
  87. go_url,
  88. title:"详情",
  89. ...toRefs(data),
  90. add
  91. };
  92. },
  93. };
  94. </script>
  95. <style scoped>
  96. .swiper{
  97. margin: 0 0.1rem;
  98. }
  99. .swiper .swiper-wrapper {
  100. /* 图片容器必须要有高度,否则下面图片不能正常显示 */
  101. height: 1.5rem;
  102. border-radius: 0.1rem;
  103. }
  104. .swiper .swiper-wrapper img{
  105. height: 100%;
  106. width: 100%;
  107. border-radius: 0.1rem;
  108. }
  109. .swiper{
  110. --swiper-pagination-color:#fff;
  111. --swiper-navigation-color:black;
  112. }
  113. .rele-wrap {
  114. background: #f5f5f5;
  115. }
  116. .has-bottom {
  117. padding-bottom: 55px !important;
  118. }
  119. .banner {
  120. position: relative;
  121. background: #fff;
  122. overflow: hidden;
  123. margin: 0;
  124. visibility: visible;
  125. height: 315px;
  126. }
  127. .banner .swipe-wrap {
  128. overflow: hidden;
  129. position: relative;
  130. }
  131. .vi_img{
  132. float: left;
  133. width: 100%;
  134. height: 100%;
  135. position: relative;
  136. }
  137. .idle-panel {
  138. padding: 1px 12px 12px 12px;
  139. background: #fff;
  140. padding-left: 12px;
  141. margin-top: 0;
  142. }
  143. .p1{
  144. font-weight: normal;
  145. line-height: 22px;
  146. padding-bottom: 0;
  147. color: #222;
  148. padding: 15px 10px 8px 0;
  149. font-size: 100%;
  150. position: relative;
  151. }
  152. .p2 {
  153. height: 20px;
  154. padding-top: 2px;
  155. padding-right:10px;
  156. color: #222;
  157. }
  158. .p2 .span{
  159. font-size: 16px;
  160. line-height: 20px;
  161. color: #ff3600;
  162. float: right;
  163. }
  164. .sale-panel{
  165. margin-top: 10px;
  166. background: #fff;
  167. padding: 1px 12px 12px 12px;
  168. }
  169. .tit{
  170. letter-spacing: 1px;
  171. color: #666;
  172. height: 14px;
  173. line-height: 14px;
  174. font-size: 14px;
  175. padding-left: 12px;
  176. position: relative;
  177. margin: 15px 0 0;
  178. }
  179. .tit::after {
  180. position: absolute;
  181. content: '';
  182. width: 2px;
  183. height: 100%;
  184. background: #56b244;
  185. left: 5px;
  186. top: 0;
  187. }
  188. .open {
  189. height: auto;
  190. text-overflow: inherit;
  191. -webkit-line-clamp: 100000;
  192. display: -webkit-box;
  193. -webkit-box-orient: vertical;
  194. overflow: hidden;
  195. line-height: 22px;
  196. margin-top: 13px;
  197. font-size: 14px;
  198. color: #333;
  199. position: relative;
  200. }
  201. .open img{
  202. width: 100%;
  203. }
  204. /* 底部按钮 */
  205. .fui-navbar{
  206. position: fixed;
  207. width: 100%;
  208. bottom: 0;
  209. z-index: 2;
  210. }
  211. .btn{
  212. border: none;
  213. font-size: 0.7rem;
  214. color: #fff;
  215. border-radius: 0;
  216. width:50%;
  217. height: 49px;
  218. }
  219. .btn_left{
  220. background: #fe9402;
  221. float:left;
  222. }
  223. .btn_right{
  224. float:right;
  225. background: #fd5555;
  226. }
  227. </style>

index.js

  1. import {request} from "./request.js";
  2. export function Index(){
  3. return request( {
  4. method : "POST",
  5. url : "Api/index"
  6. } )
  7. }
  8. export function GoodsIndex(){
  9. return request( {
  10. method : "POST",
  11. url : "Api/goods_index"
  12. } )
  13. }
  14. export function GoodsLists(data={}){
  15. return request( {
  16. method : "POST",
  17. url : "Api/goods_lists",
  18. data
  19. } )
  20. }
  21. export function GoodsDetails(data={}){
  22. return request( {
  23. method : "POST",
  24. url : "Api/goods_details",
  25. data
  26. } )
  27. }
  28. export function AddCart(data={}){
  29. return request( {
  30. method : "POST",
  31. url : "Api/add_cart",
  32. data
  33. } )
  34. }
  35. export function Login(data={}){
  36. return request( {
  37. method : "POST",
  38. url : "Api/login",
  39. data
  40. } )
  41. }
  42. export function ShopOne(data={}){
  43. return request( {
  44. method : "POST",
  45. url : "Api/shop_one",
  46. data
  47. } )
  48. }
  49. export function AddOrder(data={}){
  50. return request( {
  51. method : "POST",
  52. url : "Api/add_order",
  53. data
  54. } )
  55. }
  56. export function PayOrder(data={}){
  57. return request( {
  58. method : "POST",
  59. url : "Api/pay_order",
  60. data
  61. } )
  62. }
  63. export function Pay(data={}){
  64. return request( {
  65. method : "POST",
  66. url : "Api/pay",
  67. data
  68. } )
  69. }
  70. export function CartIndex(data={}){
  71. return request( {
  72. method : "POST",
  73. url : "Api/cart_index",
  74. data
  75. } )
  76. }
  77. export function EidtCart(data={}){
  78. return request( {
  79. method : "POST",
  80. url : "Api/eidt_cart",
  81. data
  82. } )
  83. }

Api.php

  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. use think\facade\Request;
  5. use ouyangke\Ticket;
  6. class Api{
  7. // Access to XMLHttpRequest at 'http://www.tp.com/index.php/api/Api/index'
  8. // from origin 'http://localhost:8080' has been blocked by CORS policy: No
  9. // 'Access-Control-Allow-Origin' header is present on the requested resource.
  10. // 错误信息:是因为前后端分离导致的。前后端 前端和后端的域名不是一个。不是一个,就会出现这种错误。
  11. // 跨域名访问的安全错误提示
  12. public function __construct(){
  13. // 使用php的header函数,设置为*,全部能访问
  14. header("Access-Control-Allow-Origin:*");
  15. }
  16. public function index(){
  17. // 如何写一个 前端数据接口呢?app、小程序、vue
  18. // 接口:让2个以上的项目进行数据联通,数据交互
  19. // 多个语言 必须有统一的格式, 最后返回值,必须多种语言都能使用
  20. // 接口的统一数据格式是 json
  21. // php有json的函数
  22. // json_encode 把php的数据加密成json格式
  23. // json_decode 把json格式转为 php数据格式
  24. // $arr = [
  25. // "ouyangke" => "欧阳克",
  26. // "miejue" => "灭绝师太",
  27. // "php" => [
  28. // "ouyangke",
  29. // "miejue"
  30. // ],
  31. // "tianpeng" => "朱天蓬"
  32. // ];
  33. // json格式,是文本,我们就可以echo
  34. // {"ouyangke":"\u6b27\u9633\u514b","miejue":"\u706d\u7edd\u5e08\u592a","tianpeng":"\u6731\u5929\u84ec"}
  35. // echo json_encode($arr);
  36. // 1、接口 必须用json返回数据
  37. // 2、用数组 转为json数据
  38. $ad = Db::table('oyk_adver')->where('status',1)->order('sort DESC')->select()->toArray();
  39. $lists = Db::table('oyk_shop_lists')->where('status',1)->order('add_time DESC')->limit(6)->select()->toArray();
  40. // & 取之前的地址
  41. foreach($lists as &$v){
  42. $img = explode(';',$v['img']);
  43. $v['img_s'] = $img[0];
  44. }
  45. // 3、接口只能一次性返回数据,不能多次
  46. // echo json_encode($ad);
  47. // echo json_encode($lists);
  48. $arr = [
  49. 'ad' => $ad,
  50. 'lists' => $lists
  51. ];
  52. echo json_encode($arr);
  53. }
  54. public function goods_index(){
  55. // 第一种方法:会好一些。以为php自己执行数据,比查询数据库要快
  56. // echo time();
  57. // echo '<br>';
  58. $cat = Db::table('oyk_shop_cat')->where('status',1)->order('pid,sort DESC')->select()->toArray();
  59. $tmp = [];
  60. foreach($cat as $v){
  61. if($v['pid'] == 0){
  62. // 我们可以把一级的id,作为下标。下次找的话,直接用它的id,就能找到
  63. $tmp[$v['cid']] = $v;
  64. }else{
  65. $tmp[$v['pid']]['son'][] = $v;
  66. }
  67. }
  68. // 成功是0,失败就是1,2,3,4
  69. // 4、处理接口整理数据
  70. $arr = [
  71. 'code' => 0,
  72. 'msg' => '成功',
  73. 'data' => array_merge($tmp)
  74. // 'data' => $tmp
  75. ];
  76. echo json_encode($arr);
  77. // echo time();
  78. // echo '<br>';
  79. // 能不能跟上面结合呢?
  80. // foreach($cat as $v){
  81. // if($v['pid'] != 0){
  82. // $tmp[$v['pid']]['son'][] = $v;
  83. // }
  84. // }
  85. // print_r($tmp);
  86. // 第二种方法
  87. // echo time();
  88. // echo '<br>';
  89. // $cat = Db::table('oyk_shop_cat')->where('status',1)->where('pid',0)->select()->toArray();
  90. // foreach($cat as &$v){
  91. // $v['son'] = Db::table('oyk_shop_cat')->where('status',1)->where('pid',$v['cid'])->select()->toArray();
  92. // }
  93. // echo time();
  94. // echo '<br>';
  95. // print_r($cat);
  96. }
  97. public function goods_lists(){
  98. $id = input('post.id');
  99. if(empty($id)){
  100. echo json_encode([
  101. 'code' => 1,
  102. 'msg' => '未找到列表'
  103. ]);
  104. exit;
  105. }
  106. $page = input('post.p',1);
  107. $count = Db::table('oyk_shop_lists')->where('status',1)->where('cid',$id)->count();
  108. // print_r((int)($count/5) + 1 );
  109. // ceil 函数,向上取整
  110. // print_r(ceil($count/5));
  111. $lists = Db::table('oyk_shop_lists')->where('status',1)->where('cid',$id)->page($page,5)->select()->toArray();
  112. foreach($lists as &$v){
  113. $img = explode(';',$v['img']);
  114. $v['img_s'] = $img[0];
  115. }
  116. $arr = [
  117. 'code' => 0,
  118. 'msg' => '成功',
  119. 'data' => [
  120. "lists" => $lists,
  121. 'num' => ceil($count/5)
  122. ]
  123. ];
  124. echo json_encode($arr);
  125. // exit; 不要停止
  126. }
  127. public function goods_details(){
  128. $id = input('post.id');
  129. if(empty($id)){
  130. echo json_encode([
  131. 'code' => 1,
  132. 'msg' => '未找到商品'
  133. ]);
  134. exit;
  135. }
  136. $find = Db::table('oyk_shop_lists')->where('id',$id)->find();
  137. if(!empty($find)){
  138. $find['img_s'] = explode(';',$find['img']);
  139. $find['info_s'] = explode(';',$find['info']);
  140. }
  141. echo json_encode([
  142. 'code' => 0,
  143. 'msg' => '成功',
  144. 'data' => $find
  145. ]);
  146. }
  147. public function add_cart(){
  148. $uid = input('post.uid');
  149. if(empty($uid)){
  150. echo json_encode([
  151. 'code' => 1,
  152. 'msg' => '未找到用户'
  153. ]);
  154. exit;
  155. }
  156. $sid = input('post.sid');
  157. if(empty($sid)){
  158. echo json_encode([
  159. 'code' => 1,
  160. 'msg' => '未找到商品'
  161. ]);
  162. exit;
  163. }
  164. $find = Db::table('oyk_cart')->where('sid',$sid)->where('uid',$uid)->find();
  165. if(empty($find)){
  166. $ret = Db::table('oyk_cart')->insert([
  167. 'sid' => $sid,
  168. 'uid' => $uid,
  169. 'num' => 1,
  170. 'status' => 1,
  171. 'add_time' => time()
  172. ]);
  173. }else{
  174. $ret =Db::table('oyk_cart')->where('id',$find['id'])->update([
  175. 'num' => $find['num'] + 1,
  176. 'add_time' => time()
  177. ]);
  178. }
  179. if(empty($ret)){
  180. echo json_encode([
  181. 'code' => 1,
  182. 'msg' => '添加失败'
  183. ]);
  184. exit;
  185. }
  186. echo json_encode([
  187. 'code' => 0,
  188. 'msg' => '添加成功'
  189. ]);
  190. }
  191. public function login(){
  192. $phone = input('post.phone');
  193. if(empty($phone)){
  194. echo json_encode([
  195. 'code' => 1,
  196. 'msg' => '手机号不能为空'
  197. ]);
  198. exit;
  199. }
  200. $password = input('post.password');
  201. if(empty($password)){
  202. echo json_encode([
  203. 'code' => 1,
  204. 'msg' => '密码不能为空'
  205. ]);
  206. exit;
  207. }
  208. // 如果查询用户时,用密码作为条件,我们也不知道用户是没有,还是密码错误
  209. $user = Db::table('oyk_user')->where('phone',$phone)->find();
  210. if(empty($user)){
  211. echo json_encode([
  212. 'code' => 1,
  213. 'msg' => '用户未找到'
  214. ]);
  215. exit;
  216. }
  217. if($user['password'] != md5($password)){
  218. echo json_encode([
  219. 'code' => 1,
  220. 'msg' => '密码错误'
  221. ]);
  222. exit;
  223. }
  224. unset($user['password']);
  225. $user['ticket'] = Ticket::create(1,'ouyangke');
  226. // j7bjkL9ifDhuQyxjjPQMQnLMi0c4lSYy
  227. // uV7FEN7jeJJi93RijvRP4LNCyrpiJTIg
  228. // rRTFsg3K5IuC4fzJtvYCRonI4ipKSLbr
  229. echo json_encode([
  230. 'code' => 1,
  231. 'msg' => '登录成功',
  232. 'data' => $user
  233. ]);
  234. }
  235. public function shop_one(){
  236. $token = input('post.token');
  237. if(empty($token)){
  238. echo json_encode([
  239. 'code' => 1,
  240. 'msg' => '未登录'
  241. ]);
  242. exit;
  243. }
  244. $uid = Ticket::get($token,'ouyangke');
  245. $id = input('post.id');
  246. $t = input('post.t',0);
  247. if($t == 0){
  248. $shop = Db::table('oyk_shop_lists')->where('id',$id)->select()->toArray();
  249. }else{
  250. $ids = explode(';',$id);
  251. $cart = Db::table('oyk_cart')->where('id','in',$ids)->select()->toArray();
  252. $tmp = [];
  253. foreach($cart as $v){
  254. $tmp[] = $v['sid'];
  255. }
  256. $shop = Db::table('oyk_shop_lists')->where('id','in',$tmp)->select()->toArray();
  257. $tmp_id = [];
  258. foreach($shop as $v){
  259. $tmp_id[$v['id']] = $v;
  260. }
  261. foreach($cart as $v){
  262. if($v['sid'] == $tmp_id[$v['sid']]['id'] ){
  263. $tmp_id[$v['sid']]['number'] = $v['num'];
  264. }
  265. }
  266. $shop = $tmp_id;
  267. }
  268. $total= 0;
  269. foreach($shop as &$shop_v){
  270. $img = explode(';',$shop_v['img']);
  271. $shop_v['img_s'] = $img[0];
  272. $total = $shop_v['number'] * $shop_v['price'];
  273. }
  274. $address = Db::table('oyk_user_address')->where('uid',$uid)->order('is DESC')->select()->toArray();
  275. $data = [
  276. 'shop' => $shop,
  277. 'address' => $address,
  278. 'total' => $total
  279. ];
  280. echo json_encode([
  281. 'code' => 0,
  282. 'msg' => '成功',
  283. 'data' => $data
  284. ]);
  285. }
  286. public function add_order(){
  287. $token = input('post.token');
  288. if(empty($token)){
  289. echo json_encode([
  290. 'code' => 1,
  291. 'msg' => '未登录'
  292. ]);
  293. exit;
  294. }
  295. $uid = Ticket::get($token,'ouyangke');
  296. $id = input('post.id');
  297. $shop = Db::table('oyk_shop_lists')->where('id',$id)->find();
  298. // 1、商品也需要判断id是否传
  299. // 2、在去查询商品表,是否有这个商品
  300. // 3、判断这个商品,是否被关闭status==0
  301. $data = [
  302. 'oid' => date('YmdHis',time()) . mt_rand(1000,9999) . mt_rand(1000,9999),
  303. 'uid' => $uid,
  304. 'shop_id' => $id,
  305. 'money' => $shop['price'],
  306. 'add_time' => time(),
  307. 'info' => ''
  308. ];
  309. $order_id = Db::table('oyk_user_order')->insertGetId($data);
  310. if(empty($order_id)){
  311. echo json_encode([
  312. 'code' => 1,
  313. 'msg' => '下单失败,请重试'
  314. ]);
  315. exit;
  316. }
  317. echo json_encode([
  318. 'code' => 0,
  319. 'msg' => '下单成功',
  320. 'data' => $order_id
  321. ]);
  322. }
  323. public function pay_order(){
  324. $token = input('post.token');
  325. if(empty($token)){
  326. echo json_encode([
  327. 'code' => 1,
  328. 'msg' => '未登录'
  329. ]);
  330. exit;
  331. }
  332. $uid = Ticket::get($token,'ouyangke');
  333. $id = input('post.id');
  334. $find = Db::table('oyk_user_order')->where('id',$id)->find();
  335. if(empty($find)){
  336. echo json_encode([
  337. 'code'=>1,
  338. 'msg'=>'未找到订单'
  339. ]);
  340. exit;
  341. }
  342. if($find['uid'] != $uid){
  343. echo json_encode([
  344. 'code'=>1,
  345. 'msg'=>'未找到订单'
  346. ]);
  347. exit;
  348. }
  349. if($find['status'] == 0){
  350. echo json_encode([
  351. 'code'=>1,
  352. 'msg'=>'订单已关闭'
  353. ]);
  354. exit;
  355. }
  356. if($find['status'] != 1){
  357. echo json_encode([
  358. 'code'=>1,
  359. 'msg'=>'订单已支付'
  360. ]);
  361. exit;
  362. }
  363. echo json_encode([
  364. 'code' => 0,
  365. 'msg' => '成功',
  366. 'data' => $find
  367. ]);
  368. }
  369. public function pay(){
  370. $token = input('post.token');
  371. if(empty($token)){
  372. echo json_encode([
  373. 'code' => 1,
  374. 'msg' => '未登录'
  375. ]);
  376. exit;
  377. }
  378. $uid = Ticket::get($token,'ouyangke');
  379. $id = input('post.id');
  380. $is_pay = input('post.is_pay');
  381. $update = Db::table('oyk_user_order')->where('id',$id)->update([
  382. 'pay_type' => $is_pay,
  383. 'pay_time' => time(),
  384. 'status' => 2
  385. ]);
  386. if(empty($update)){
  387. echo json_encode([
  388. 'code' => 1,
  389. 'msg' => '支付失败'
  390. ]);
  391. exit;
  392. }
  393. echo json_encode([
  394. 'code' => 0,
  395. 'msg' => '支付成功'
  396. ]);
  397. }
  398. public function cart_index(){
  399. $token = input('post.token');
  400. if(empty($token)){
  401. echo json_encode([
  402. 'code' => 1,
  403. 'msg' => '未登录'
  404. ]);
  405. exit;
  406. }
  407. $uid = Ticket::get($token,'ouyangke');
  408. $cart = Db::table('oyk_cart')->where('uid',$uid)->order('add_time DESC')->select()->toArray();
  409. if(!empty($cart)){
  410. $tmp = [];
  411. foreach($cart as $v){
  412. $tmp[] = $v['sid'];
  413. }
  414. $shop = Db::table('oyk_shop_lists')->where('id','in',$tmp)->select()->toArray();
  415. $tmp_shop = [];
  416. foreach($shop as $shop_v){
  417. $img = explode(';',$shop_v['img']);
  418. $shop_v['img_s'] = $img[0];
  419. $tmp_shop[$shop_v['id']] = $shop_v;
  420. }
  421. foreach($cart as &$cart_v){
  422. if($tmp_shop[$cart_v['sid']]['id'] == $cart_v['sid'] )
  423. $cart_v['shop'] = $tmp_shop[$cart_v['sid']];
  424. }
  425. }
  426. echo json_encode([
  427. 'code' => 0,
  428. 'msg' => '成功',
  429. 'data' => $cart
  430. ]);
  431. }
  432. public function eidt_cart(){
  433. $token = input('post.token');
  434. if(empty($token)){
  435. echo json_encode([
  436. 'code' => 1,
  437. 'msg' => '未登录'
  438. ]);
  439. exit;
  440. }
  441. $uid = Ticket::get($token,'ouyangke');
  442. $id = input('post.id');
  443. $num = input('post.num');
  444. $update = Db::table('oyk_cart')->where('id',$id)->update([
  445. 'num' => $num
  446. ]);
  447. if(empty($update)){
  448. echo json_encode([
  449. 'code' => 1,
  450. 'msg' => '修改失败'
  451. ]);
  452. exit;
  453. }
  454. echo json_encode([
  455. 'code' => 0,
  456. 'msg' => '成功'
  457. ]);
  458. }
  459. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!