HexiaoController.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author zcy
  7. *
  8. */
  9. namespace Home\Controller;
  10. /**
  11. * 核销员核销
  12. * Class HexiaoController
  13. * @package Home\Controller
  14. */
  15. class HexiaoController extends CommonController {
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. /**
  20. * 核销员管理页面
  21. */
  22. public function hexiao_manage()
  23. {
  24. $_GPC = I('request.');
  25. $token = $_GPC['token'];
  26. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  27. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  28. {
  29. echo json_encode( array('code' => 1) );
  30. die();
  31. }
  32. $member_id = $weprogram_token['member_id'];
  33. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  34. if( $salesmember_id <= 0 )
  35. {
  36. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  37. die();
  38. }
  39. $data = array();
  40. //核销员门店信息
  41. $salesroom_list = D('Home/Salesroom')->get_salesrooms_by_smember_id($salesmember_id);
  42. $data['salesroom_list'] = $salesroom_list;
  43. //核销员今日核销记录
  44. $saleshexiao_record_list = D('Home/Salesroom')->get_today_hexiao_record_by_smember_id($salesmember_id);
  45. //核销员信息
  46. $salesroom_member = M('lionfish_comshop_salesroom_member')->where( array('id' => $salesmember_id) )->find();
  47. if(!empty($salesroom_member['last_salesroom_id'])){
  48. $salesroom = M('lionfish_comshop_salesroom')->where( array('id' => $salesroom_member['last_salesroom_id']) )->find();
  49. $salesroom_member['last_salesroom'] = $salesroom;
  50. }
  51. $data['salesroom_member'] = $salesroom_member;
  52. $data['saleshexiao_record_list'] = $saleshexiao_record_list;
  53. $data['today_saleshexiao_count'] = count($saleshexiao_record_list);
  54. echo json_encode( array('code' => 0, 'data' => $data) );
  55. }
  56. /**
  57. * 核销订单页面
  58. */
  59. public function hexiao_order_info(){
  60. $_GPC = I('request.');
  61. $token = $_GPC['token'];
  62. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  63. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  64. {
  65. echo json_encode( array('code' => 1) );
  66. die();
  67. }
  68. $member_id = $weprogram_token['member_id'];
  69. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  70. if( $salesmember_id <= 0 )
  71. {
  72. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  73. die();
  74. }
  75. $hexiao_volume_code = $_GPC['hexiao_volume_code'];
  76. if( empty($hexiao_volume_code) )
  77. {
  78. echo json_encode( array('code' => 3, 'msg' => '核销码不存在' ) );
  79. die();
  80. }
  81. $hexiao_info = D('Home/Salesroom')->get_hexiao_order_by_code($hexiao_volume_code,$salesmember_id);
  82. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $hexiao_info['orders']['order_id']) )->find();
  83. if($order_info['order_status_id'] == 5){
  84. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  85. die();
  86. }
  87. if($order_info['order_status_id'] == 3){
  88. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  89. die();
  90. }
  91. if($hexiao_info['is_exist'] == 0){
  92. echo json_encode( array('code' => 3, 'msg' => '请输入正确的手机号/券码' ) );
  93. die();
  94. }
  95. if($hexiao_info['is_exist'] == 2){
  96. echo json_encode( array('code' => 3, 'msg' => '核销员无核销权限' ) );
  97. die();
  98. }
  99. if($hexiao_info['is_exist'] == 4){
  100. echo json_encode( array('code' => 3, 'msg' => '该手机号无到店核销订单' ) );
  101. die();
  102. }
  103. echo json_encode( array('code' => 0, 'data' => $hexiao_info) );
  104. }
  105. /**
  106. * 核销整个订单
  107. */
  108. public function all_hx_order(){
  109. $_GPC = I('request.');
  110. $token = $_GPC['token'];
  111. $order_id = $_GPC['order_id'];
  112. $salesroom_id = $_GPC['salesroom_id'];
  113. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  114. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  115. {
  116. echo json_encode( array('code' => 1) );
  117. die();
  118. }
  119. $member_id = $weprogram_token['member_id'];
  120. if( empty($order_id) )
  121. {
  122. echo json_encode( array('code' => 3, 'msg' => '订单已全部核销,无法操作' ) );
  123. die();
  124. }
  125. $order_info = M('lionfish_comshop_order')->where( 'order_id in('.$order_id.')' )->select();
  126. if( empty($order_info) )
  127. {
  128. echo json_encode( array('code' => 3, 'msg' => '订单信息不存在' ) );
  129. die();
  130. }
  131. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  132. if( $salesmember_id <= 0 )
  133. {
  134. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  135. die();
  136. }
  137. $hx_order_count = 0 ;
  138. $oeders_hx_result = array();
  139. foreach($order_info as $var){
  140. if($var['order_status_id'] == 5){
  141. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  142. die();
  143. }
  144. if($var['order_status_id'] == 3){
  145. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  146. die();
  147. }
  148. if($var['order_status_id'] != 4){
  149. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  150. die();
  151. }
  152. $hx_result = D('Home/Salesroom')->hexiao_all_orders($var['order_id'],$salesmember_id,$salesroom_id);
  153. if($hx_result['hx_goods_count'] > 0){
  154. $hx_order_count += 1;
  155. }else{
  156. echo json_encode( array('code' => 3, 'msg' => '无核销商品') );
  157. }
  158. }
  159. if($hx_order_count > 0 ){
  160. $oeders_hx_result['hx_order_count'] = $hx_order_count;
  161. echo json_encode( array('code' => 0, 'data' => $oeders_hx_result) );
  162. }
  163. }
  164. /**
  165. * 核销商品(按订单核销的商品)
  166. */
  167. public function hx_order_goods(){
  168. $_GPC = I('request.');
  169. $token = $_GPC['token'];
  170. $hexiao_id = $_GPC['hexiao_id'];
  171. $salesroom_id = $_GPC['salesroom_id'];
  172. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  173. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  174. {
  175. echo json_encode( array('code' => 1) );
  176. die();
  177. }
  178. $member_id = $weprogram_token['member_id'];
  179. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  180. if( empty($saleshexiao_info) )
  181. {
  182. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  183. die();
  184. }
  185. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  186. if( $salesmember_id <= 0 )
  187. {
  188. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  189. die();
  190. }
  191. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $saleshexiao_info['order_id']) )->find();
  192. if($order_info['order_status_id'] == 5){
  193. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  194. die();
  195. }
  196. if($order_info['order_status_id'] == 3){
  197. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  198. die();
  199. }
  200. if($order_info['order_status_id'] != 4){
  201. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  202. die();
  203. }
  204. $hx_result = D('Home/Salesroom')->saleshexiao_order_goods($saleshexiao_info,$salesmember_id,$salesroom_id, 0);
  205. if($hx_result == 1){
  206. echo json_encode( array('code' => 0) );
  207. }else if($hx_result == 0){
  208. echo json_encode( array('code' => 3, 'msg' => '核销商品失败') );
  209. }else{
  210. echo json_encode( array('code' => 3, 'msg' => '无核销权限') );
  211. }
  212. }
  213. /**
  214. * 按次核销点击弹窗(按次核销商品)
  215. */
  216. public function get_hxgoods_bytimes(){
  217. $_GPC = I('request.');
  218. $token = $_GPC['token'];
  219. $hexiao_id = $_GPC['hexiao_id'];
  220. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  221. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  222. {
  223. echo json_encode( array('code' => 1) );
  224. die();
  225. }
  226. $member_id = $weprogram_token['member_id'];
  227. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  228. if( empty($saleshexiao_info) )
  229. {
  230. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  231. die();
  232. }
  233. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  234. if( $salesmember_id <= 0 )
  235. {
  236. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  237. die();
  238. }
  239. $hx_info = D('Home/Salesroom')->get_hxgoods_bytimes($saleshexiao_info,$salesmember_id);
  240. if($hx_info['status'] == -1){
  241. echo json_encode( array('code' => 3, 'msg' => '无核销权限' ) );
  242. die();
  243. }
  244. echo json_encode( array('code' => 0, 'data' => $hx_info) );
  245. }
  246. /**
  247. * 按次核销商品一次性核销完成
  248. */
  249. public function all_hx_order_goods_bytimes(){
  250. $_GPC = I('request.');
  251. $token = $_GPC['token'];
  252. //核销商品订单表id
  253. $hexiao_id = $_GPC['hexiao_id'];
  254. //门店id
  255. $salesroom_id = $_GPC['salesroom_id'];
  256. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  257. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  258. {
  259. echo json_encode( array('code' => 1) );
  260. die();
  261. }
  262. $member_id = $weprogram_token['member_id'];
  263. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  264. if( empty($saleshexiao_info) )
  265. {
  266. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  267. die();
  268. }
  269. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  270. if( $salesmember_id <= 0 )
  271. {
  272. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  273. die();
  274. }
  275. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $saleshexiao_info['order_id']) )->find();
  276. if($order_info['order_status_id'] == 5){
  277. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  278. die();
  279. }
  280. if($order_info['order_status_id'] == 3){
  281. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  282. die();
  283. }
  284. if($order_info['order_status_id'] != 4){
  285. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  286. die();
  287. }
  288. $hx_result = D('Home/Salesroom')->saleshexiao_order_goods($saleshexiao_info,$salesmember_id,$salesroom_id,0);
  289. if($hx_result == 1){
  290. echo json_encode( array('code' => 0) );
  291. }else if($hx_result == 0){
  292. echo json_encode( array('code' => 3, 'msg' => '核销商品失败') );
  293. }else{
  294. echo json_encode( array('code' => 3, 'msg' => '无核销权限') );
  295. }
  296. }
  297. /**
  298. * 核销商品(按次数核销的商品)
  299. */
  300. public function hx_order_goods_bytimes(){
  301. $_GPC = I('request.');
  302. $token = $_GPC['token'];
  303. //核销商品订单表id
  304. $hexiao_id = $_GPC['hexiao_id'];
  305. //门店id
  306. $salesroom_id = $_GPC['salesroom_id'];
  307. //核销次数
  308. $hx_times = $_GPC['hx_times'];
  309. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  310. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  311. {
  312. echo json_encode( array('code' => 1) );
  313. die();
  314. }
  315. if( empty($hx_times) || intval($hx_times) < 1 )
  316. {
  317. echo json_encode( array('code' => 3, 'msg' => '核销次数错误' ) );
  318. die();
  319. }
  320. $member_id = $weprogram_token['member_id'];
  321. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  322. if( empty($saleshexiao_info) )
  323. {
  324. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  325. die();
  326. }
  327. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  328. if( $salesmember_id <= 0 )
  329. {
  330. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  331. die();
  332. }
  333. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $saleshexiao_info['order_id']) )->find();
  334. if($order_info['order_status_id'] == 5){
  335. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  336. die();
  337. }
  338. if($order_info['order_status_id'] == 3){
  339. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  340. die();
  341. }
  342. if($order_info['order_status_id'] != 4){
  343. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  344. die();
  345. }
  346. $hx_result = D('Home/Salesroom')->saleshexiao_order_goods($saleshexiao_info,$salesmember_id,$salesroom_id,$hx_times);
  347. if($hx_result == 1){
  348. echo json_encode( array('code' => 0) );
  349. }else if($hx_result == 0){
  350. echo json_encode( array('code' => 3, 'msg' => '核销商品失败') );
  351. }else{
  352. echo json_encode( array('code' => 3, 'msg' => '无核销权限') );
  353. }
  354. }
  355. /**
  356. * 核销员切换门店
  357. */
  358. public function hexiao_change_salesroom(){
  359. $_GPC = I('request.');
  360. $token = $_GPC['token'];
  361. $salesroom_id = $_GPC['salesroom_id'];
  362. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  363. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  364. {
  365. echo json_encode( array('code' => 1) );
  366. die();
  367. }
  368. $member_id = $weprogram_token['member_id'];
  369. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  370. if( $salesmember_id <= 0 )
  371. {
  372. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  373. die();
  374. }
  375. M('lionfish_comshop_salesroom_member')->where( array('id' => $salesmember_id ) )->save( array('last_salesroom_id' => $salesroom_id) );
  376. echo json_encode( array('code' => 0) );
  377. }
  378. }