Index.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\StockConfig;
  4. use app\common\model\ShopList;
  5. use app\common\model\StockLog;
  6. use think\exception\ValidateException;
  7. use app\api\validate\Stock as StockValidate;
  8. use app\common\model\StockDetail;
  9. use think\facade\Db;
  10. class Index extends Base
  11. {
  12. //首页数据分组统计品种
  13. public function index(StockLog $stockLog)
  14. {
  15. $data= $stockLog->where('user_id', $this->userinfo['id'])
  16. ->field('type,count(id) as count')
  17. ->group('type')
  18. ->select();
  19. $this->success('ok', $data);
  20. }
  21. //库存统计
  22. public function statistics(StockConfig $stockConfig, StockDetail $stockDetail)
  23. {
  24. $result = [];
  25. $list = $stockConfig->where('status', $stockConfig::StatusNormal)->field('id,type_id,title')
  26. ->orderRaw("field('variety_name','packing_box','material')")->select();
  27. foreach ($list as $item) {
  28. switch ($item['type_id']) {
  29. case $stockConfig::VarietyName:
  30. $result['variety_name'][] = [
  31. 'name' => $item->title,
  32. 'num' => $stockDetail->where('key', $item['id'])->value('num')
  33. ];
  34. break;
  35. case $stockConfig::PackingBox:
  36. $result['packing_box'][] = [
  37. 'name' => $item->title,
  38. 'num' => $stockDetail->where('key', $item['id'])->value('num')
  39. ];
  40. break;
  41. case $stockConfig::Material:
  42. $result['material'][] = [
  43. 'name' => $item->title,
  44. 'num' => $stockDetail->where('key', $item['id'])->value('num')
  45. ];
  46. break;
  47. }
  48. }
  49. $this->success('ok', $result);
  50. }
  51. /**
  52. * @return void 全部平台
  53. */
  54. public function getPlatform()
  55. {
  56. $list = site_config('addonsd.platform_list');
  57. $this->success('提交成功', $list);
  58. }
  59. //获取店铺
  60. public function getShop(ShopList $shopList){
  61. $platform_id = $this->request->post('platform_id/d');
  62. if(empty($platform_id)){
  63. $this->error('参数有误');
  64. }
  65. return $this->success('ok', $shopList->where('platform', $platform_id)->column('name', 'id'));
  66. }
  67. //获取规格
  68. public function getSpec(ShopList $shopList){
  69. $shop_id = $this->request->post('shop_id/d');
  70. if( empty($shop_id)){
  71. $this->error('参数有误');
  72. }
  73. $spec = $shopList->where('id', $shop_id)->value('type_spec');
  74. $shopList = $spec?json_decode($spec, true): [];
  75. return $this->success('ok', $shopList);
  76. }
  77. }