Sellerindex.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. namespace app\api\controller;
  3. /**
  4. * ============================================================================
  5. *
  6. * ============================================================================
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * ============================================================================
  11. * 卖家中心控制器
  12. */
  13. class Sellerindex extends MobileSeller {
  14. public function initialize() {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. }
  17. /**
  18. * @api {POST} api/Sellerindex/index 商家中心
  19. * @apiVersion 1.0.0
  20. * @apiGroup Sellerindex
  21. *
  22. * @apiHeader {String} X-DS-KEY 卖家授权token
  23. *
  24. * @apiSuccess {String} code 返回码,10000为成功
  25. * @apiSuccess {String} message 返回消息
  26. * @apiSuccess {Object} result 返回数据
  27. * @apiSuccess {Object} result.seller_info 卖家信息
  28. * @apiSuccess {Int} result.seller_info.goods_lockup 违规商品数
  29. * @apiSuccess {Int} result.seller_info.goods_offline 下架商品数
  30. * @apiSuccess {Int} result.seller_info.goods_online 上架商品数
  31. * @apiSuccess {Int} result.seller_info.is_admin 是否主账号 0否1是
  32. * @apiSuccess {Int} result.seller_info.last_logintime 上次登录时间
  33. * @apiSuccess {Int} result.seller_info.last_logintime_fmt 上次登录时间描述
  34. * @apiSuccess {Int} result.seller_info.member_id 用户ID
  35. * @apiSuccess {Int} result.seller_info.order_nopay_count 待付款订单数
  36. * @apiSuccess {Int} result.seller_info.order_noreceipt_count 待收货订单数
  37. * @apiSuccess {Int} result.seller_info.order_noship_count 待发货订单数
  38. * @apiSuccess {Int} result.seller_info.seller_clienttype 客户端
  39. * @apiSuccess {Int} result.seller_info.seller_id 卖家账号ID
  40. * @apiSuccess {Int} result.seller_info.seller_name 卖家账号名称
  41. * @apiSuccess {Int} result.seller_info.sellergroup_id 卖家账号组
  42. * @apiSuccess {Int} result.seller_info.store_id 店铺ID
  43. * @apiSuccess {Object} result.statics 统计信息
  44. * @apiSuccess {Int} result.statics.bill_confirm 待确认结算单数
  45. * @apiSuccess {Int} result.statics.complain 投诉数
  46. * @apiSuccess {Int} result.statics.consult 咨询数
  47. * @apiSuccess {Int} result.statics.delivery 待发货订单数
  48. * @apiSuccess {Int} result.statics.goodscount 商品数
  49. * @apiSuccess {Int} result.statics.imagecount 图片数
  50. * @apiSuccess {Int} result.statics.lockup 违商品规数
  51. * @apiSuccess {Int} result.statics.offline 下架商品数
  52. * @apiSuccess {Int} result.statics.online 上架商品数
  53. * @apiSuccess {Int} result.statics.payment 已付款订单数
  54. * @apiSuccess {Int} result.statics.progressing 交易中订单数
  55. * @apiSuccess {Int} result.statics.refund 退款数
  56. * @apiSuccess {Int} result.statics.refund_lock 退款中数
  57. * @apiSuccess {Int} result.statics.return 退货数
  58. * @apiSuccess {Int} result.statics.return_lock 退货中数
  59. * @apiSuccess {Int} result.statics.verifyfail 审核失败商品数
  60. * @apiSuccess {Int} result.statics.waitverify 等待审核商品数
  61. * @apiSuccess {Object} result.store_info 店铺信息 (返回字段参考store表)
  62. * @apiSuccess {Object} result.store_info.daily_sales 今日销量
  63. * @apiSuccess {Float} result.store_info.daily_sales.orderamount 订单金额
  64. * @apiSuccess {Int} result.store_info.daily_sales.ordernum 订单量
  65. * @apiSuccess {Int} result.store_info.goods_count 商品数量
  66. * @apiSuccess {Int} result.store_info.grade_albumlimit 商品图片限制,0不限制
  67. * @apiSuccess {Int} result.store_info.grade_goodslimit 商品数量限制,0不限制
  68. * @apiSuccess {Int} result.store_info.grade_id 店铺等级
  69. * @apiSuccess {Int} result.store_info.grade_name 店铺等级名称
  70. * @apiSuccess {Object} result.store_info.monthly_sales 月销量
  71. * @apiSuccess {Float} result.store_info.monthly_sales.orderamount 订单金额
  72. * @apiSuccess {Int} result.store_info.monthly_sales.ordernum 订单量
  73. */
  74. public function index() {
  75. $seller_info = array();
  76. $seller_info = $this->seller_info;
  77. $store_info = $this->store_info;
  78. //最后登陆
  79. $seller_info['last_logintime_fmt'] = date('Y-m-d H:i:s', $seller_info['last_logintime']);
  80. $order_model = model('order');
  81. // 待付款
  82. $seller_info['order_nopay_count'] = intval($order_model->getOrderCountByID('store', $store_info['store_id'], 'NewCount'));
  83. // 待发货
  84. $seller_info['order_noship_count'] = intval($order_model->getOrderCountByID('store', $store_info['store_id'], 'PayCount'));
  85. // 待收货
  86. $seller_info['order_noreceipt_count'] = intval($order_model->getOrderCountByID('store', $store_info['store_id'], 'SendCount'));
  87. $goods_model = model('goods');
  88. // 出售中的商品
  89. $seller_info['goods_online'] = $goods_model->getGoodsCommonOnlineCount(array(array('store_id' ,'=', $store_info['store_id'])));
  90. // 仓库待上架的商品
  91. $seller_info['goods_offline'] = $goods_model->getGoodsCommonOfflineCount(array(array('store_id' ,'=', $store_info['store_id'])));
  92. // 违规下架的商品
  93. $seller_info['goods_lockup'] = $goods_model->getGoodsCommonLockUpCount(array(array('store_id' ,'=', $store_info['store_id'])));
  94. //店铺头像
  95. $store_info['store_avatar'] = get_store_logo($store_info['store_avatar'], 'store_avatar');
  96. //店铺标志
  97. $store_info['store_logo'] = get_store_logo($store_info['store_logo'], 'store_logo');
  98. //等级信息
  99. $store_info['grade_name'] = $this->store_grade['storegrade_name'];
  100. //商品数量限制
  101. $store_info['grade_goodslimit'] = $this->store_grade['storegrade_goods_limit'];
  102. //图片空间数量限制
  103. $store_info['grade_albumlimit'] = $this->store_grade['storegrade_album_limit'];
  104. /**
  105. * 销售情况统计
  106. */
  107. $field = 'COUNT(*) as ordernum,SUM(order_amount) as orderamount';
  108. $where = array();
  109. $where[] = array('store_id', '=', $this->store_info['store_id']);
  110. //有效订单
  111. $where[] = array('order_isvalid', '=', 1);
  112. //昨日销量
  113. $where[] = array('order_add_time', 'between', array(strtotime(date('Y-m-d', (TIMESTAMP - 3600 * 24))), strtotime(date('Y-m-d', TIMESTAMP)) - 1));
  114. $daily_sales = model('stat')->getoneByStatorder($where, $field);
  115. //月销量
  116. $where[] = array('order_add_time', '>', strtotime(date('Y-m', TIMESTAMP)));
  117. $monthly_sales = model('stat')->getoneByStatorder($where, $field);
  118. $store_info['daily_sales'] = $daily_sales;
  119. $store_info['monthly_sales'] = $monthly_sales;
  120. //统计
  121. $statics = $this->getStatics();
  122. ds_json_encode(10000, '', array('seller_info' => $seller_info, 'store_info' => $store_info, 'statics' => $statics));
  123. }
  124. /**
  125. * @api {POST} api/Sellerindex/getStatics 取得卖家统计类信息
  126. * @apiVersion 1.0.0
  127. * @apiGroup Sellerindex
  128. *
  129. * @apiHeader {String} X-DS-KEY 卖家授权token
  130. *
  131. * @apiSuccess {String} code 返回码,10000为成功
  132. * @apiSuccess {String} message 返回消息
  133. * @apiSuccess {Object} result 返回数据
  134. */
  135. private function getStatics() {
  136. $add_time_to = strtotime(date("Y-m-d")) + 60 * 60 * 24; //当前日期 ,从零点来时
  137. $add_time_from = strtotime(date("Y-m-d", (strtotime(date("Y-m-d")) - 60 * 60 * 24 * 30))); //30天前
  138. $goods_online = 0; // 出售中商品
  139. $goods_waitverify = 0; // 等待审核
  140. $goods_verifyfail = 0; // 审核失败
  141. $goods_offline = 0; // 仓库待上架商品
  142. $goods_lockup = 0; // 违规下架商品
  143. $consult = 0; // 待回复商品咨询
  144. $no_payment = 0; // 待付款
  145. $no_delivery = 0; // 待发货
  146. $no_receipt = 0; // 待收货
  147. $refund_lock = 0; // 售前退款
  148. $refund = 0; // 售后退款
  149. $return_lock = 0; // 售前退货
  150. $return = 0; // 售后退货
  151. $complain = 0; //进行中投诉
  152. $goods_model = model('goods');
  153. // 全部商品数
  154. $goodscount = $goods_model->getGoodsCommonCount(array('store_id' => $this->store_info['store_id']));
  155. // 出售中的商品
  156. $goods_online = $goods_model->getGoodsCommonOnlineCount(array(array('store_id' ,'=', $this->store_info['store_id'])));
  157. if (config('ds_config.goods_verify')) {
  158. // 等待审核的商品
  159. $goods_waitverify = $goods_model->getGoodsCommonWaitVerifyCount(array(array('store_id' ,'=', $this->store_info['store_id'])));
  160. // 审核失败的商品
  161. $goods_verifyfail = $goods_model->getGoodsCommonVerifyFailCount(array(array('store_id' ,'=', $this->store_info['store_id'])));
  162. }
  163. // 仓库待上架的商品
  164. $goods_offline = $goods_model->getGoodsCommonOfflineCount(array(array('store_id' ,'=', $this->store_info['store_id'])));
  165. // 违规下架的商品
  166. $goods_lockup = $goods_model->getGoodsCommonLockUpCount(array(array('store_id' ,'=', $this->store_info['store_id'])));
  167. // 等待回复商品咨询
  168. $consult = model('consult')->getConsultCount(array('store_id' => $this->store_info['store_id'], 'consult_reply' => ''));
  169. // 商品图片数量
  170. $imagecount = model('album')->getAlbumpicCount(array('store_id' => $this->store_info['store_id']));
  171. $order_model = model('order');
  172. // 交易中的订单
  173. $progressing = $order_model->getOrderCountByID('store', $this->store_info['store_id'], 'TradeCount');
  174. // 待付款
  175. $no_payment = $order_model->getOrderCountByID('store', $this->store_info['store_id'], 'NewCount');
  176. // 待发货
  177. $no_delivery = $order_model->getOrderCountByID('store', $this->store_info['store_id'], 'PayCount');
  178. $refundreturn_model = model('refundreturn');
  179. // 售前退款
  180. $condition = array();
  181. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  182. $condition[] = array('refund_type', '=', 1);
  183. $condition[] = array('order_lock', '=', 2);
  184. $condition[] = array('refund_state', '<', 3);
  185. $refund_lock = $refundreturn_model->getRefundreturnCount($condition);
  186. // 售后退款
  187. $condition = array();
  188. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  189. $condition[] = array('refund_type', '=', 1);
  190. $condition[] = array('order_lock', '=', 1);
  191. $condition[] = array('refund_state', '<', 3);
  192. $refund = $refundreturn_model->getRefundreturnCount($condition);
  193. // 售前退货
  194. $condition = array();
  195. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  196. $condition[] = array('refund_type', '=', 2);
  197. $condition[] = array('order_lock', '=', 2);
  198. $condition[] = array('refund_state', '<', 3);
  199. $return_lock = $refundreturn_model->getRefundreturnCount($condition);
  200. // 售后退货
  201. $condition = array();
  202. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  203. $condition[] = array('refund_type', '=', 2);
  204. $condition[] = array('order_lock', '=', 1);
  205. $condition[] = array('refund_state', '<', 3);
  206. $return = $refundreturn_model->getRefundreturnCount($condition);
  207. $condition = array();
  208. $condition[] = array('accused_id', '=', $this->store_info['store_id']);
  209. $condition[] = array('complain_state', 'between', array(10, 90));
  210. $complain_model = model('complain');
  211. $complain = $complain_model->getComplainCount($condition);
  212. //待确认的结算账单
  213. $bill_model = model('bill');
  214. $condition = array();
  215. $condition[] = array('ob_store_id','=',$this->store_info['store_id']);
  216. $condition[] = array('ob_state','=',BILL_STATE_CREATE);
  217. $bill_confirm_count = $bill_model->getOrderbillCount($condition);
  218. //统计数组
  219. $statistics = array(
  220. 'goodscount' => $goodscount,
  221. 'online' => $goods_online,
  222. 'waitverify' => $goods_waitverify,
  223. 'verifyfail' => $goods_verifyfail,
  224. 'offline' => $goods_offline,
  225. 'lockup' => $goods_lockup,
  226. 'imagecount' => $imagecount,
  227. 'consult' => $consult,
  228. 'progressing' => $progressing,
  229. 'payment' => $no_payment,
  230. 'delivery' => $no_delivery,
  231. 'refund_lock' => $refund_lock,
  232. 'refund' => $refund,
  233. 'return_lock' => $return_lock,
  234. 'return' => $return,
  235. 'complain' => $complain,
  236. 'bill_confirm' => $bill_confirm_count
  237. );
  238. return $statistics;
  239. }
  240. }