Index.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\cashier\shop\controller;
  11. use addon\cashier\model\Cashier;
  12. use app\model\store\Store;
  13. use app\model\system\Api;
  14. use app\shop\controller\BaseShop;
  15. use app\model\system\User;
  16. /**
  17. * Class Index
  18. * @package addon\cashier\shop\controller
  19. */
  20. class Index extends BaseShop
  21. {
  22. public function cashier()
  23. {
  24. $store_id = input('store_id', 0);
  25. $user_model = new User();
  26. $userinfo = $user_model->getUserInfo([ [ 'uid', '=', $this->user_info[ 'uid' ] ] ], 'uid,app_module,site_id,group_id,group_name,username,status,is_admin,password')[ 'data' ];
  27. if ($userinfo[ 'is_admin' ]) {
  28. $store_info = ( new Store() )->getDefaultStore($userinfo[ 'site_id' ])[ 'data' ] ?? [];
  29. if (empty($user_info[ 'user_group_list' ])) {
  30. $userinfo[ 'user_group_list' ] = [ $store_info ];
  31. } else {
  32. $store_list = array_column($userinfo[ 'user_group_list' ], null, 'store_id');
  33. if (!isset($store_list[ $store_info[ 'store_id' ] ])) array_push($userinfo[ 'user_group_list' ], $store_info);
  34. }
  35. }
  36. if (!$store_id && isset($userinfo[ 'user_group_list' ][ 0 ])) $store_id = $userinfo[ 'user_group_list' ][ 0 ][ 'store_id' ];
  37. $store_ids = array_column($userinfo[ 'user_group_list' ], 'store_id');
  38. $token = $this->createToken($userinfo, ( 86400 * 7 ));
  39. $this->assign('store_id', in_array($store_id, $store_ids) ? $store_id : 0);
  40. $this->assign('token', $token);
  41. $this->assign('url', ROOT_URL . '/cashregister');
  42. return $this->fetch("index/cashier");
  43. }
  44. /**
  45. * 创建token
  46. * @param $user_info
  47. * @return string
  48. */
  49. private function createToken($user_info)
  50. {
  51. $api_config = ( new Api() )->getApiConfig()[ 'data' ];
  52. $data = [
  53. 'user_info' => $user_info,
  54. 'expire_time' => $api_config[ 'value' ][ 'long_time' ] * 3600
  55. ];
  56. if ($api_config[ 'is_use' ] && isset($api_config[ 'value' ][ 'private_key' ]) && !empty($api_config[ 'value' ][ 'private_key' ])) {
  57. $token = encrypt(json_encode($data), $api_config[ 'value' ][ 'private_key' ]);
  58. } else {
  59. $token = encrypt(json_encode($data));
  60. }
  61. return $token;
  62. }
  63. /**
  64. * 收银端部署
  65. * @return mixed
  66. */
  67. public function deploy()
  68. {
  69. return $this->fetch("addon/cashier/shop/view/index/deploy.html");
  70. }
  71. /**
  72. * 刷新收银端
  73. */
  74. public function refreshCashier()
  75. {
  76. return ( new Cashier() )->refreshCashier();
  77. }
  78. /**
  79. * 下载收银端uniapp源码
  80. */
  81. public function downloadCashier()
  82. {
  83. $res = ( new Cashier() )->downloadOs();
  84. echo $res[ 'message' ];
  85. }
  86. }