Index.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. *
  4. * User: anyluck
  5. * Date: 2020/6/3
  6. * Time: 10:22
  7. */
  8. namespace app\web\controller;
  9. use app\common\controller\Orde;
  10. use app\common\model\Banner;
  11. use app\common\model\Message;
  12. use app\common\model\Mining;
  13. use app\common\model\Notice;
  14. use app\common\model\Order;
  15. use app\common\model\State;
  16. use app\common\model\User;
  17. use app\web\model\Back;
  18. use app\web\model\Msg;
  19. use app\web\model\Orders;
  20. class Index extends Base
  21. {
  22. // todo 首页
  23. // 首页
  24. public function index()
  25. {
  26. $data=[];
  27. $message_count=Message::where(["status"=>0,"user_id"=>$this->user_id])->count();
  28. $data["message_count"]=$message_count;// 未读消息
  29. $banner=Banner::where(["status"=>0])->field("id,image")->select();
  30. $data["banner"]=$banner;// 轮播图
  31. // 公告
  32. $notice=Notice::where(["status"=>0])->field("id,name")->select();
  33. $data["notice"]=$notice;
  34. // 交易区块
  35. $back=Back::back();
  36. $data["back"]=$back;
  37. json_result(200,"",$data);
  38. }
  39. // 轮播图详情
  40. public function banner_show()
  41. {
  42. $id=input("id");
  43. $where["id"]=$id;
  44. $data=Banner::where($where)->find();
  45. json_result(200,"",$data);
  46. }
  47. // 获取交易区块
  48. public function back()
  49. {
  50. $back=Back::back();
  51. json_result(200,"",$back);
  52. }
  53. // 根据个人信息查询交易区块
  54. public function persion_back()
  55. {
  56. $back=Back::persion_back($this->user_id);
  57. json_result(200,"",$back);
  58. }
  59. // 交易数据列表
  60. public function order_list()
  61. {
  62. $page=input("page")?:1;
  63. $limit=input("limit")?:10;
  64. $type=input("type")?:0;// 0是查看交易中心求购数据 1我的购买数据 2我的卖出数据
  65. $status=input("status");//0 不根据状态查询 1 查找进行中的 2 已完成的 配合上面的type 一起使用
  66. $num=input("num")?:0;// 查看交易中心是传的区块数量 0 是全部
  67. $user_id=$this->user_id;
  68. $res=Orders::order_list($type,$user_id,$status,$page,$limit,$num);
  69. json_result(200,"",$res);
  70. }
  71. // 买入和卖出
  72. public function order_buy()
  73. {
  74. $type=input("type")?:0;
  75. $mining_id=input("mining_id")?:0;
  76. $order_id=input("order_id");
  77. Orders::push_order($this->user,$this->user_id,$type,$order_id,$mining_id);
  78. }
  79. // 订单详情
  80. public function order_show()
  81. {
  82. $id=input("id");if (!$id)json_result(400,"请上传订单id");
  83. $order=Order::where(["id"=>$id])->find();
  84. if (!$order){
  85. json_result(400,"订单不存在");
  86. }
  87. if ($order->buy_user&&$order->push_user){
  88. Orders::order_show($order,$this->user_id);
  89. }else{
  90. json_result(400,"当前订单未卖出无法查询卖出人信息");
  91. }
  92. }
  93. //上传凭证
  94. public function order_voucher()
  95. {
  96. $id=input("id");if (!$id)json_result(400,"订单id 没有上传");
  97. $image=input("image");if ($image)json_result(400,"请上传凭证");
  98. $where["id"]=$id;
  99. $order=Order::where($where)->find();
  100. if (!$order){
  101. json_result(400,"订单id错误");
  102. }
  103. if ($order->status!=1){
  104. json_result(400,"当前状态无法上传凭证");
  105. }
  106. // 给用户短信或者邮件通知
  107. $where_user["id"]=$order->push_user;
  108. $user=User::where($where_user)->find();
  109. $content="您的订单买家已经打款请前去查看";
  110. \app\common\controller\Message::add_message($order->push_user,2,"买家已付款","您在".$order->number."区的订单,编号【".$order->order."】,买家已付款,请审核");
  111. //dump($user);die();
  112. Order::update(["image"=>$image,"status"=>2],$where);
  113. if ($user->phone){
  114. Msg::phone($content,$user->phone);
  115. }else{
  116. Msg::mail($content,$user->mail);
  117. }
  118. json_result(200,"操作成功");
  119. }
  120. // 审核成功
  121. public function order_success()
  122. {
  123. $id=input("id");
  124. $where["id"]=$id;
  125. $order=Order::where($where)->find();
  126. if (!$order){
  127. json_result(400,"订单id错误");
  128. }
  129. if ($order->status==3){
  130. json_result(400,"订单已经完成");
  131. }
  132. if ($order->status!=2){
  133. json_result(400,"还没有上传证明");
  134. }
  135. Orde::order_success($order);
  136. json_result(200,"处理成功");
  137. }
  138. // 审核失败
  139. public function order_fail()
  140. {
  141. $id=input("id");if (!$id)json_result(400,"请上传订单id");
  142. $msg=input("msg");if (!$msg)json_result(400,"请添加失败原因");
  143. Orders::order_fail($msg,$id);
  144. }
  145. // 取消交易
  146. public function Order_Cancel ()
  147. {
  148. $id=input("id");
  149. $where["id"]=$id;
  150. $order=Order::where(["id"=>$id])->find();
  151. if ($order->status==0){
  152. // 修改订单状态
  153. $update["status"]=4;
  154. Order::update($update,["id"=>$id]);
  155. json_result(200,"取消成功");
  156. }else{
  157. json_result(400,"不能取消");
  158. }
  159. }
  160. // 申述
  161. public function state()
  162. {
  163. $order_id=input("order_id");
  164. $content=input("content");if (!$content)json_result(400,"请填写申述内容");
  165. $image=input("image");
  166. $add["add_time"]=time();
  167. $add["user_id"]=$this->user_id;
  168. $add["order"]=$order_id;
  169. $add["content"]=$content;
  170. $add["image"]=$image;
  171. State::create($add);
  172. json_result(200,"申述提交成功");
  173. }
  174. }