Index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. protected $noNeedLogin = ['getAppVersion'];
  13. //首页数据分组统计品种
  14. public function index(StockLog $stockLog)
  15. {
  16. $data= $stockLog->where('user_id', $this->userinfo['id'])
  17. ->field('type,count(id) as count')
  18. ->group('type')
  19. ->select();
  20. $this->success('ok', $data);
  21. }
  22. //库存统计
  23. public function statistics(StockConfig $stockConfig, StockDetail $stockDetail)
  24. {
  25. $result = [];
  26. $list = $stockConfig->where('status', $stockConfig::StatusNormal)->field('id,type_id,title')
  27. ->orderRaw("field('variety_name','packing_box','material')")->select();
  28. foreach ($list as $item) {
  29. switch ($item['type_id']) {
  30. case $stockConfig::VarietyName:
  31. $result['variety_name'][] = [
  32. 'name' => $item->title,
  33. 'num' => $stockDetail->where('key', $item['id'])->value('num')
  34. ];
  35. break;
  36. case $stockConfig::PackingBox:
  37. $result['packing_box'][] = [
  38. 'name' => $item->title,
  39. 'num' => $stockDetail->where('key', $item['id'])->value('num')
  40. ];
  41. break;
  42. case $stockConfig::Material:
  43. $result['material'][] = [
  44. 'name' => $item->title,
  45. 'num' => $stockDetail->where('key', $item['id'])->value('num')
  46. ];
  47. break;
  48. }
  49. }
  50. $this->success('ok', $result);
  51. }
  52. //app版本升级配置
  53. public function getAppVersion(){
  54. $this->success('ok',
  55. ['version' => site_config('addonsd.app_version'),
  56. 'url' => site_config('addonsd.app_address'),
  57. 'content' => site_config('addonsd.app_describe')]);
  58. }
  59. /**
  60. * @return void 全部平台
  61. */
  62. public function getPlatform()
  63. {
  64. $list = site_config('addonsd.platform_list');
  65. $this->success('提交成功', $list);
  66. }
  67. //获取店铺
  68. public function getShop(ShopList $shopList){
  69. $platform_id = $this->request->post('platform_id/d');
  70. if(empty($platform_id)){
  71. $this->error('参数有误');
  72. }
  73. return $this->success('ok', $shopList->where('platform', $platform_id)->column('name', 'id'));
  74. }
  75. //获取规格
  76. public function getSpec(ShopList $shopList){
  77. $shop_id = $this->request->post('shop_id/d');
  78. if( empty($shop_id)){
  79. $this->error('参数有误');
  80. }
  81. $spec = $shopList->where('id', $shop_id)->value('type_spec');
  82. $shopList = $spec?json_decode($spec, true): [];
  83. return $this->success('ok', $shopList);
  84. }
  85. }