Data.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. //数据统计类(数据看板,获取相关统计数据)
  7. class Data extends BaseController
  8. {
  9. /**
  10. * public function index()
  11. * {
  12. * $data = [];
  13. *
  14. * // //1.今日销量(单数、金额)
  15. * // $today_sales_volume = Db::name('sale')
  16. * // ->field('count(id) orders_number,sum(total_price) money')
  17. * // ->where('is_del',0)
  18. * // ->whereDay('addtime','today')
  19. * // ->find();
  20. * //
  21. * // $data['today_sales_volume'] = [
  22. * // 'orders_number' => isset($today_sales_volume['orders_number'])?$today_sales_volume['orders_number']:0,
  23. * // 'money' => isset($today_sales_volume['money'])?$today_sales_volume['money']:0,
  24. * // ];
  25. *
  26. * //2.今日销冠(部门、姓名、单数、金额)
  27. * $temp = Db::name('sale')
  28. * ->field('count(id) orders,sum(total_price) money,apply_id')
  29. * ->where('is_del', 0)
  30. * ->whereDay('addtime', 'today')
  31. * ->group('apply_id')
  32. * ->order('money', 'desc')
  33. * ->limit(1)
  34. * ->buildSql();
  35. *
  36. * $data['today_sales_champion'] = Db::table($temp)
  37. * ->alias('t')
  38. * ->field('t.apply_id,t.orders,t.money,u.itemid company_id, c.`name` company, u.nickname')
  39. * ->leftJoin('depart_user u', 'u.uid=t.apply_id AND u.is_del=0')
  40. * ->leftJoin('company_item c', 'c.id=u.itemid AND c.is_del=0')
  41. * ->select()
  42. * ->toArray();
  43. *
  44. * //3.今日采购(采购订单数量、商品数量、竞价单数、反馈商品数)
  45. * $data['today_purchase'] = [
  46. * 'orders' => '0',
  47. * 'goods' => '0',
  48. * 'bidding_orders' => '0',
  49. * 'feedback_goods' => '0'
  50. * ];
  51. *
  52. * //4.今日订单列表(按照完成率排序,前三名的部门、单数、金额)
  53. * $data['today_order'] = [
  54. * ['company' => 'xxx部', 'orders' => '30', 'money' => '300'],
  55. * ['company' => 'xx部', 'orders' => '20', 'money' => '200'],
  56. * ['company' => 'x部', 'orders' => '10', 'money' => '100'],
  57. * ];
  58. *
  59. * //5.本月完成率列表(按照完成率排序,前三名的部门、完成单数和完成率,区分今日、本周、本月和毛利率状态:2达标、1最低、0不达标等情况)
  60. * $data['month_completion_rate'] = [
  61. * 'today' => [
  62. * ['company' => 'xxx部', 'completion' => 10, 'completion_rate' => '30%', 'type' => '2'],
  63. * ['company' => 'xx部', 'completion' => 10, 'completion_rate' => '20%', 'type' => '1'],
  64. * ['company' => 'x部', 'completion' => 10, 'completion_rate' => '10%', 'type' => '0'],
  65. * ],
  66. * 'week' => [
  67. * ['company' => 'xxx部', 'completion' => 10, 'completion_rate' => '30%', 'type' => '2'],
  68. * ['company' => 'xx部', 'completion' => 10, 'completion_rate' => '20%', 'type' => '1'],
  69. * ['company' => 'x部', 'completion' => 10, 'completion_rate' => '10%', 'type' => '0'],
  70. * ],
  71. * 'month' => [
  72. * ['company' => 'xxx部', 'completion' => 10, 'completion_rate' => '30%', 'type' => '2'],
  73. * ['company' => 'xx部', 'completion' => 10, 'completion_rate' => '20%', 'type' => '1'],
  74. * ['company' => 'x部', 'completion' => 10, 'completion_rate' => '10%', 'type' => '0'],
  75. * ],
  76. * ];
  77. *
  78. * //6.待开票(单数、金额)
  79. * $data['wait_invoice'] = [
  80. * 'orders' => '10',
  81. * 'money' => '34.45'
  82. * ];
  83. *
  84. * //7.待回款(单数、金额)
  85. * $data['wait_return'] = [
  86. * 'orders' => '100',
  87. * 'money' => '3.45'
  88. * ];
  89. *
  90. * //8.待回票(单数、金额)
  91. * $data['wait_ticket'] = [
  92. * 'orders' => '8',
  93. * 'money' => '38.5'
  94. * ];
  95. *
  96. * //9.待付款(单数、金额)
  97. * $data['wait_payment'] = [
  98. * 'orders' => '34',
  99. * 'money' => '5338.58'
  100. * ];
  101. *
  102. *
  103. * //10.竞价(招标单数、未竞标单数)
  104. * $data['bidding'] = [
  105. * 'bidding_orders' => '10',
  106. * 'no_bidding_orders' => '2'
  107. * ];
  108. *
  109. * //11.采购单(采购单数、未下单数)
  110. * $data['purchase'] = [
  111. * 'purchase_orders' => '10',
  112. * 'no_purchase_orders' => '2'
  113. * ];
  114. *
  115. * //12.采购单(采购下单数、未生产单数)
  116. * $data['purchase_2'] = [
  117. * 'orders' => '10',
  118. * 'no_orders' => '2'
  119. * ];
  120. *
  121. * //13.未发货(单数、商品数)
  122. * $data['no_deliver'] = [
  123. * 'orders' => '10',
  124. * 'goods' => '2'
  125. * ];
  126. *
  127. * //14.转单率(部门名称、今日转单率、本月转单率,今年转单率,按照年度转单率排序)
  128. * $data['transfer_order_rate'] = [
  129. * ['company' => 'xxx部', 'today_tor' => '34%', 'month_tor' => '68%', 'year_tor' => '45%'],
  130. * ['company' => 'xx部', 'today_tor' => '34%', 'month_tor' => '68%', 'year_tor' => '40%'],
  131. * ['company' => 'x部', 'today_tor' => '34%', 'month_tor' => '68%', 'year_tor' => '6%'],
  132. * ];
  133. *
  134. * return app_show(0, '请求成功', $data);
  135. *
  136. * }
  137. **/
  138. //1.今日销量
  139. public function todaySalesVolume()
  140. {
  141. $rs = Db::name('sale')
  142. ->field('count(id) orders_number,sum(total_price) money')
  143. ->where('is_del', 0)
  144. ->whereDay('addtime', 'today')
  145. ->find();
  146. $temp = [
  147. 'orders_number' => isset($rs['orders_number']) ? $rs['orders_number'] : 0,
  148. 'money' => isset($rs['money']) ? $rs['money'] : 0,
  149. ];
  150. return app_show(0, '请求成功', $temp);
  151. }
  152. //2.今日销冠
  153. public function todaySalesChampion()
  154. {
  155. $temp = Db::name('sale')
  156. ->field('count(id) orders,sum(total_price) money,apply_id')
  157. ->where('is_del', 0)
  158. ->whereDay('addtime', 'today')
  159. ->group('apply_id')
  160. ->order('money', 'desc')
  161. ->limit(1)
  162. ->buildSql();
  163. $rs = Db::table($temp)
  164. ->alias('t')
  165. ->field('t.apply_id,t.orders,t.money,u.itemid company_id, c.`name` company, u.nickname')
  166. ->leftJoin('depart_user u', 'u.uid=t.apply_id AND u.is_del=0')
  167. ->leftJoin('company_item c', 'c.id=u.itemid AND c.is_del=0')
  168. ->select()
  169. ->toArray();
  170. return app_show(0, '请求成功', empty($rs[0]) ? [] : $rs[0]);
  171. }
  172. //3.今日采购
  173. public function todayPurchase()
  174. {
  175. $rs = Db::name('purchease_order')
  176. ->field('count(id) orders_number,sum(good_num) good_num')
  177. ->where('is_del', 0)
  178. ->whereDay('addtime', 'today')
  179. ->find();
  180. $consult_info_total = Db::name('consult_info')
  181. ->where('is_del', 0)
  182. ->whereDay('addtime', 'today')
  183. ->count('id');
  184. $consult_bids_total = Db::name('consult_bids')
  185. ->where('is_del', 0)
  186. ->whereDay('addtime', 'today')
  187. ->count('id');
  188. $data = [
  189. 'orders_number' => isset($rs['orders_number']) ? $rs['orders_number'] : 0,
  190. 'good_num' => isset($rs['good_num']) ? $rs['good_num'] : 0,
  191. 'consult_info_total' => $consult_info_total,
  192. 'consult_bids_total' => $consult_bids_total,
  193. ];
  194. return app_show(0, '请求成功', $data);
  195. }
  196. //4.票(相关,暂不做)
  197. //5.竞价单和采购单
  198. public function totalZixunPurchease()
  199. {
  200. //招标单数(咨询单数)
  201. $zixun_total = Db::name('consult_info')
  202. ->where('is_del', 0)
  203. ->count('id');
  204. //已反馈单数
  205. $zixun_bids = Db::name('consult_bids')
  206. ->where('is_del', 0)
  207. ->count('id');
  208. //未竞价单数(未反馈单数)
  209. $not_feedback = $zixun_total - $zixun_bids;
  210. //采购单数
  211. $purchease_total = Db::name('purchease_order')
  212. ->where('is_del', 0)
  213. ->count('id');
  214. //采购单未下单数(状态为待与供应商确认)
  215. $purchease_wait_confirm = Db::name('purchease_order')
  216. ->where(['is_del' => 0, 'status' => 0])
  217. ->count('id');
  218. return app_show(0, '请求成功', [
  219. 'zixun_total' => $zixun_total,
  220. 'not_feedback' => $not_feedback,
  221. 'purchease_total' => $purchease_total,
  222. 'purchease_wait_confirm' => $purchease_wait_confirm,
  223. ]);
  224. }
  225. //6.未发货
  226. public function waitSendTotal()
  227. {
  228. return 123;
  229. }
  230. //7.今日订单
  231. public function todaySale()
  232. {
  233. $temp = Db::name('sale')
  234. ->alias('s')
  235. ->field('s.id,s.apply_id,s.total_price,u.nickname,u.itemid')
  236. ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
  237. ->where('s.is_del', 0)
  238. ->whereDay('s.addtime', 'today')
  239. ->buildSql();
  240. $rs = Db::table($temp)
  241. ->alias('t')
  242. ->field('itemid companyId,c.`name` companyName,SUM(t.total_price) total_price,COUNT(t.id) total_order')
  243. ->leftJoin('company_item c', 'c.id=t.itemid')
  244. ->group('t.itemid')
  245. ->order('total_price', 'desc')
  246. ->limit(3)
  247. ->select()
  248. ->toArray();
  249. return app_show(0, '请求成功', $rs);
  250. }
  251. //8.本月完成率(数据在结算库里)
  252. public function monthFinishRate()
  253. {
  254. }
  255. //9.转单率-今日
  256. public function orderTransferRateToday(){
  257. // sale order_type==2 咨询生成订单数
  258. }
  259. //9.转单率-本月
  260. public function orderTransferRateMonth(){
  261. }
  262. //9.转单率-今年
  263. public function orderTransferRateYear(){
  264. }
  265. }