Index.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 think\facade\Db;
  9. class Index extends Base
  10. {
  11. //首页数据分组统计品种
  12. public function index(StockLog $stockLog)
  13. {
  14. $data= $stockLog->where('user_id', $this->userinfo['id'])
  15. ->field('type,count(id) as count')
  16. ->group('type')
  17. ->select();
  18. $this->success('ok', $data);
  19. }
  20. //库存统计
  21. public function statistics(StockConfig $stockConfig)
  22. {
  23. $list = $stockConfig->alias('a')->where('a.status', $stockConfig::StatusNormal)
  24. ->leftjoin('stock_detail b', 'a.id = b.key')
  25. ->field('a.id, a.type_id,a.title,b.num')
  26. ->select();
  27. dump($list->toArray());die;// StockConfig::Status::NORMAL
  28. $this->success('ok', $list);
  29. }
  30. /**
  31. * @return void 全部平台
  32. */
  33. public function getPlatform()
  34. {
  35. $list = site_config('addonsd.platform_list');
  36. $this->success('提交成功', $list);
  37. }
  38. //获取店铺
  39. public function getShop(ShopList $shopList){
  40. $platform_id = $this->request->post('platform_id/d');
  41. if(empty($platform_id)){
  42. $this->error('参数有误');
  43. }
  44. return $this->success('ok', $shopList->where('platform', $platform_id)->column('name', 'id'));
  45. }
  46. //获取规格
  47. public function getSpec(ShopList $shopList){
  48. $shop_id = $this->request->post('shop_id/d');
  49. if( empty($shop_id)){
  50. $this->error('参数有误');
  51. }
  52. $spec = $shopList->where('id', $shop_id)->value('type_spec');
  53. $shopList = $spec?json_decode($spec, true): [];
  54. return $this->success('ok', $shopList);
  55. }
  56. }